<template>
  <div class="page-container page-container-create">
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>营销中心</el-breadcrumb-item>
        <el-breadcrumb-item>通用促销</el-breadcrumb-item>
        <el-breadcrumb-item>创建单一活动</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <p class="font22 mb20" v-if="promotionId && promotionId != '0'">编辑单一活动</p>
    <p class="font22 mb20" v-else>创建单一活动</p>
    <!-- 添加商品 -->
    <el-dialog :visible.sync="dialogVisibleTwo" title="添加商品" :close-on-click-modal="false">
      <div>
        <div>
          <el-form inline :model="productForm" ref="productForm" :size="size" :rules="productFormRules">
            <div class="col-sm-9">
              <el-form-item label="商品名称：" prop="chineseName" class="w178 mb30" label-width="112px">
                <el-input v-model="productForm.chineseName" auto-complete="off" clearable  placeholder="商品名称" maxlength="80"></el-input>
              </el-form-item>
              <el-form-item label="商品编码：" prop="code" class="w178" >
                <el-input v-model="productForm.code" auto-complete="off" clearable  placeholder="商品编码" maxlength="80"></el-input>
              </el-form-item>
              <el-form-item label="商品类目：" prop="categoryName" class="w178" >
                <el-input v-model="productForm.categoryName" auto-complete="off" clearable  placeholder="商品类目" maxlength="80"></el-input>
              </el-form-item>
              <el-form-item label="所属商户：" prop="storeName" class="w178">
                <el-input v-model="productForm.storeName" auto-complete="off" clearable  placeholder="所属商户" maxlength="80"></el-input>
              </el-form-item>
              <el-form-item label="商户Code：" prop="storeCode" class="w178">
                <el-input v-model="productForm.storeCode" auto-complete="off" clearable  placeholder="商户Code" maxlength="80"></el-input>
              </el-form-item>
            </div>
          </el-form>

          <el-row class="mb30 mt20 t_r">
            <el-button class="resetButton" size="mini" @click="resetProductForm()" icon="el-icon-refresh">重置</el-button>
            <el-button class="searchButton" size="mini" @click="productFormFind(1)" icon="el-icon-search">搜索</el-button>
            <!-- <el-button class="searchButton" size="mini" @click="addAllProduct()">全部添加</el-button> -->
          </el-row>
        </div>
        <div>
          <el-table
            :data="tableDataTwo"
            @selection-change="addSelectionChangeProduct"
            :header-cell-style="tableHeaderColor"
            ref="multipleTable"
            :row-class-name="tableRowClassName"
            v-loading="tableDataTwoLoading"
            :size="size"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="code" label="商品编码" sortable align="center"></el-table-column>
            <el-table-column prop="chineseName" label="商品名称" align="center"></el-table-column>
            <el-table-column label="商品类目" align="center">
              <template slot-scope="scope">
                {{scope.row.goodsCategory || '-'}}
              </template>
            </el-table-column>
            <el-table-column prop="storeName" label="所属商户" align="center"></el-table-column>
            <el-table-column prop="salePriceScope" label="原价（元）" align="center"></el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar t_r" v-if="tableDataTwo.length > 0">
            <el-pagination
              @size-change="producthandleSizeChange"
              @current-change="producthandleCurrentChange"
              :current-page="productForm.start"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="productForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="productListTotal"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button class="cancelButton" plain :size="size" @click.native="dialogVisibleTwo = false">取消</el-button>
        <el-button
          :size="size"
          class="searchButton"
          @click.native="dialogVisibleTwo = false"
          @click="productTableData2Click"
          :loading="productEditLoading"
        >确定</el-button>
      </div>
    </el-dialog>
    <!--审核弹框-->
    <el-dialog
      title="管理员备注"
      class="el-dialog-style"
      :visible.sync="dialogVisibleAdmin"
      :close-on-click-modal="false"
      @closed="handleClose"
    >
      <el-form
        :model="adminDataForm"
        label-width="100%"
        :size="size"
        ref="adminDataForm"
        :rules="adminDataFormRules"
        label-position="right"
        inline
      >
        <el-form-item prop="auditRemark" class="textarea">
          <el-input
            type="textarea"
            placeholder="请输入备注"
            v-model="adminDataForm.auditRemark"
            :rows="4"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="submitFormAdminNotPass" class="cancelButton">不通过</el-button>
        <el-button :size="size" type="primary" @click.native="submitFormAdmin"  class="searchButton">通过</el-button>
      </div>
    </el-dialog>

    <!--工具栏-->
    <div class="toolbar">
      <div class="stepset" >
        <ul>
          <li :class="{'active':active>=1}"><span>1</span><p>设置促销规则</p></li>
          <!-- <li :class="{'active':active>=2}"><span>2</span><p>设置活动商家/店铺</p></li> -->
          <li :class="{'active':active>=3}"><span>2</span><p>设置活动商品</p></li>
          <li :class="{'active':active>=4}"><span>3</span><p>创建成功</p></li>
        </ul>
      </div>
      <div v-show="active==1" class="content create_stepOne createSet create_stepAlso">
        <el-form
          :inline="true"
          :model="filters"
          :rules="filtersRules"
          ref="filters"
          :label-position="labelPosition"
          label-width="140px"
        >
          <div>
            <div class="title">基本设置：</div>
            <div class="item">
              <el-row class="m_b30">
                <el-form-item label="活动名称：" prop="promName" class="wid color999">
                  <el-input
                    type="text"
                    v-model.trim="filters.promName"
                    placeholder="请输入3-60个字符之间"
                    maxlength="60"
                    minlength="3"
                    class="input"
                    clearable
                  />
                </el-form-item>
              </el-row>

              <el-row class="m_b30">
                <el-form-item label="活动时间：" prop="promotionStartEndTime" class="wid w450">
                  <el-date-picker
                    v-model="filters.promotionStartEndTime"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :picker-options="timeCheck"
                  ></el-date-picker>
                </el-form-item>
              </el-row>
              <el-row class="m_b30">
                <el-form-item label="活动搜索词：" prop="searchKeyword" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.searchKeyword"
                    placeholder="多个搜索词可用数据逗号“,”隔开"
                    class="input" clearable
                  />
                </el-form-item>
              </el-row>

               <el-row class="m_b30">
                <el-form-item label="活动费用预算：" prop="budget" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.budget"
                    placeholder="请输入平台营销费用"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    class="input" clearable
                  /><span>元</span>
                </el-form-item>
              </el-row>
              <el-row class="m_b30">
                <el-form-item label="预警比例：" prop="warningNum" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.warningNum"
                    placeholder="请输入预警比例："
                    class="input" clearable
                    oninput="value=value.replace(/[^\d]/g,'')"
                  /><span>%</span>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div>
            <div class="title">活动规则：</div>
            <div class="item">
              <el-row class="m_b30 labelAlignment">
                <el-form-item label="活动类型：" prop="frontPromType" class="wid">
                  <el-radio-group v-model="filters.frontPromType">
                    <el-radio :label="1" border class="form-radio mr40 radioAlignment noMarginLeft w144 t_l">特价促销</el-radio>
                    <el-radio :label="2" border class="form-radio mr40 radioAlignment noMarginLeft w144 t_l">折扣促销</el-radio>
                    <el-radio :label="3" border class="form-radio radioAlignment noMarginLeft w144 t_l">直降促销</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-row>

              <el-row class="labelAlignment">
                <el-form-item label="活动描述：" prop="description" class="wid">
                  <el-input
                    class="activityDesc"
                    type="textarea"
                    :rows="2"
                    :placeholder="genDescriptionPlaceholder()"
                    v-model="filters.description"
                    clearable
                    maxlength="100"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label class="wid">
                  <div
                    class="desc color666"
                  >注：非必填字段，不填将显示系统默认文案（会存在某些促销类型无系统默认文案）。自定义输入活动描述后将显示在前台商品详情页中，请慎重填写。</div>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div class="w100">
            <div class="title">交易规则：</div>
            <div class="item">

              <el-row class="m_b52 labelAlignment">
                <el-form-item label="超限规则：" prop="overLimitRule" class="wid">
                  <el-radio-group v-model="filters.overLimitRule">
                    <el-radio :label="1" border class="form-radio mr40 radioAlignment t_l noMarginLeft">按原价购买</el-radio>
                    <el-radio :label="2" border class="form-radio radioAlignment w144 t_l noMarginLeft">不可购买</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label class="wid">
                  <div
                    class="desc color666"
                  >注：“超限规则”指用户购买商品数量超过活动可购买数量（通过活动设置的“个人限购数、活动总限购数、每单限购数”计算出）后的购买规则</div>
                </el-form-item>
              </el-row>

              <el-row class="m_b60 ways labelAlignment" v-if="deptType != 3">
                <el-form-item label="是否分摊：" prop="costAllocationFlag" class="wid">
                  <el-row class="m_b52">
                    <el-radio-group v-model="filters.costAllocationFlag">
                      <el-radio :label="1" border class="form-radio mr40 radioAlignment w144 t_l noMarginLeft">是</el-radio>
                      <el-radio :label="0" border class="form-radio radioAlignment w144 t_l noMarginLeft">否</el-radio>
                    </el-radio-group>
                  </el-row>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div class="w100">
            <div class="title">参与条件：</div>
            <div class="item">
              <el-row class="m_b52 labelAlignment">
                <el-form-item label="新老用户：" prop="selectUserType" class="wid t_r" label-width="141px">
                  <div class="flex">
                    <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w144 t_l mleft10" border :indeterminate="userTypeIsIndeterminate" v-model="userTypeCheckAll" @change="handleCheckAllUserTypeChange">全选</el-checkbox>
                   <el-checkbox-group v-model="selectUserType" @change="handleCheckedUserTypeChange">
                      <el-checkbox border :label="1" :key="1" class="mr40 el-checkBox-padding noMarginLeft w144 t_l">新用户</el-checkbox>
                      <el-checkbox border :label="2" :key="2" class="el-checkBox-padding noMarginLeft w144 t_l">老用户</el-checkbox>
                    </el-checkbox-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row class="m_b52 labelAlignment">
                <el-form-item label="会员类型：" prop="selectMemTypes" class="wid" >
                  <div class="flex">
                    <el-checkbox border :indeterminate="memTypeIsIndeterminate" v-model="memTypeCheckAll" @change="handleCheckAllMemTypeChange" class=" w144 t_l mr40 el-checkBox-padding noMarginLeft mleft10" >全选</el-checkbox>
                    <el-checkbox-group v-model="selectMemTypes" @change="handleCheckedMemTypeChange">
                      <el-checkbox border :label="1" :key="1" class="mr40 el-checkBox-padding noMarginLeft w144 t_l" >普通会员</el-checkbox>
                      <el-checkbox border :label="2" :key="2" class="el-checkBox-padding noMarginLeft w144 t_l">we2000</el-checkbox>
                      <el-checkbox border :label="3" :key="3" class="el-checkBox-padding noMarginLeft w144 t_l">分期会员</el-checkbox>
                    </el-checkbox-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row class="m_b52 labelAlignment">
                <el-form-item label="渠道入口：" prop="channelId" class="wid t_r" label-width="140px">
                  <div class="flex">
                    <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10" border :indeterminate="channelIdIsIndeterminate" v-model="channelIdCheckAll" @change="handleCheckAllChannelIdChange">全选</el-checkbox>
                    <el-checkbox-group v-model="channelId" @change="handleCheckedChannelIdChange">
                      <el-checkbox :label="1" :key="1" border class="mr40 el-checkBox-padding noMarginLeft">企业微信</el-checkbox>
                      <el-checkbox :label="2" :key="2" border class="mr40 el-checkBox-padding noMarginLeft">xxx</el-checkbox>
                      <el-checkbox :label="3" :key="3" border class="mr40 el-checkBox-padding noMarginLeft">yyy</el-checkbox>
                    </el-checkbox-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="备注：" class="wid">
                  <el-input
                    type="textarea"
                    v-model="filters.remark"
                    @input="changeRemark($event)"
                    placeholder="请输入备注"
                    class="remarks h286"
                    clearable
                  ></el-input>
                </el-form-item>
              </el-row>
            </div>
          </div>
        </el-form>
      </div>

      <!--促销商品列表-->
      <div v-if="active == 3" class="tab-container createSet active3">
        <!-- tabs -->
        <el-tabs v-model="productStatusTabs" @tab-click="productTabs">
          <el-tab-pane :label="'生效商品('+ (Number(merchantProductTotalCount) > 9999 ? '9999+' : merchantProductTotalCount) +')'" name="1">
            <div class="row-line-button t_r">
              <div style="width:100%">
                <el-button
                  class="searchButton"
                  size="mini"
                  @click="changeSearchMerchantProductFlag"
                  icon="el-icon-search"
                >搜索</el-button>
                <!-- <el-button type="primary" size="mini" @click="addAllProduct">全部添加</el-button> -->
                <el-button class="searchButton" size="mini" @click="add">添加促销商品</el-button>
                <el-button class="resetButton" @click="batchDelProduct">批量删除</el-button>
              </div>
            </div>

            <el-row>
              <div v-if="searchMerchantProductFlag">
                <el-form
                  :inline="true"
                  :model="merchantProductSearchForm"
                  size="mini"
                  ref="merchantProductSearchForm"
                  class="rightForm"
                  :rules="merchantProductSearchFormRules"
                >
                  <el-form-item label="商户：" prop="storeId" class="mb30">
                    <template>
                      <el-select v-model="merchantProductSearchForm.storeId" placeholder="全部" clearable>
                        <el-option
                          v-for="item in promotionStoreTableData"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                          clearable
                        ></el-option>
                      </el-select>
                    </template>
                  </el-form-item>

                  <el-form-item label="商品编码：" prop="mpCode" class="mb30">
                    <el-input v-model="merchantProductSearchForm.mpCode" clearable placeholder="商品编码" maxlength="80"></el-input>
                  </el-form-item>
                  <el-form-item label="商品名称：" prop="mpName" class="mb30">
                    <el-input v-model="merchantProductSearchForm.mpName" clearable placeholder="商品名称" maxlength="80"></el-input>
                  </el-form-item>
                  <el-form-item label="商品类目：" prop="categoryName" class="mb30">
                    <el-input v-model="merchantProductSearchForm.categoryName" clearable placeholder="商品类目" maxlength="80"></el-input>
                  </el-form-item>
                  <el-form-item class="mb30">
                    <el-button class="resetButton" size="mini" @click="resetMerchantProductSearch()">重置</el-button>
                    <el-button class="resetButton" size="mini" @click="merchantProductSearch()">查询</el-button>

                  </el-form-item>
                </el-form>
              </div>
            </el-row>
            <div class="tableTree">

              <el-table :data="merchantProductTableData" row-key="id" default-expand-all :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                        @selection-change="repelSelectionChange"  class="tableStyle" v-loading="merchantProductTableDataLoading">
                <!-- <el-table-column type="selection" width="55"></el-table-column> -->
                <el-table-column align="left" width="30">
                  <template slot="header" slot-scope="scope">
                    <div class="isAllChecked" v-if="merchantProductTableData.length > 0">
                      <el-checkbox
                        :indeterminate="isIndeterminateProductCheck"
                        v-model="isAllProductChecked"
                        @change="handleCheckedAllProductChange"
                      ></el-checkbox>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="40">
                  <template slot-scope="scope">
                    <el-checkbox
                      :indeterminate="scope.row.isIndeterminateCheck"
                      v-model="scope.row.isCheck"
                      @change="handleCheckedProductChange(scope.row,$event)"
                    ></el-checkbox>
                  </template>
                </el-table-column>
                <el-table-column prop="mpCode" label="商品编码" width="200" align="left"></el-table-column>
                <el-table-column prop="productName" label="商品名称" width="200" sortable align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.mpName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="storeName" label="商品分类" align="center" width="200">
                  <template slot-scope="scope">
                    <span>{{ scope.row.categoryName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="stock" label="库存" align="center" width="200">
                  <template slot-scope="scope">
                    <span>{{ scope.row.stock}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="storeName" label="所属商户" align="center" width="200">
                  <template slot-scope="scope">
                    <span>{{ scope.row.storeName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="storeName" label="商户Code" align="center" width="200">
                  <template slot-scope="scope">
                    <span>{{ scope.row.storeName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="salePrice" label="零售价（元）" align="center" width="200">
                  <template slot-scope="scope">
                    <span>{{ scope.row.salePrice}}</span>
                  </template>
                </el-table-column>


                <el-table-column
                  prop="contentValue"
                  label="*特价"
                  align="center"
                  v-if="this.filters.frontPromType == 1"
                  width="200"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.contentValue"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="特价"
                      :disabled="scope.row.disabled"
                      oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="contentValue"
                  label="*折扣"
                  align="center"
                  v-if="this.filters.frontPromType == 2"
                  width="200"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.contentValue"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="折扣"
                      :disabled="scope.row.disabled"
                      clearable
                      maxlength="3"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="contentValue"
                  label="*直降"
                  align="center"
                  v-if="this.filters.frontPromType == 3"
                  width="200"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.contentValue"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="直降"
                      :disabled="scope.row.disabled"
                      oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="parentAllocationScale" v-if="filters.costAllocationFlag == '1'" label="平台分摊" align="center" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.parentAllocationScale"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="平台分摊"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="merchantAllocationScale" v-if="filters.costAllocationFlag == '1'" label="商户分摊" align="center" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.merchantAllocationScale"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="商户分摊"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="stockLimit" label="活动库存" align="center" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.stockLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="活动库存"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="individualLimit" label="个人限购" align="center" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.individualLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="个人限购"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="orderLimit" label="订单限购" align="center" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.orderLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="订单限购"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="390">
                  <template slot-scope="scope">
                    <el-button
                      @click.native.prevent="delMerchantProducts(scope.row.id)"
                      type="text"
                    >删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!--分页栏-->
              <div class="toolbar t_r">
                <el-pagination
                  @size-change="handleSizeChangeMerchantProductTableData"
                  @current-change="handleCurrentChangeMerchantProductTableData"
                  :current-page="merchantProductSearchForm.start"
                  :page-sizes="[10]"
                  style="float:right;"
                  :page-size="merchantProductSearchForm.limit"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="merchantProductTableDataTotal"
                ></el-pagination>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="'互斥商品('+ (Number(mutexMerchantProductTotalCount) > 9999 ? '9999+' : mutexMerchantProductTotalCount) +')'" name="2">
            <div class="row-line-button t_r">
              <div style="width:100%">
                <!-- <el-button type="primary" size="mini" @click="addAllProduct">全部添加</el-button> -->
                <!-- <el-button type="primary" size="mini" @click="add">添加促销商品</el-button> -->
                <!-- <el-button class="searchButton"  @click="batchRenewAdd">批量重新添加</el-button> -->
              </div>
            </div>
            <div class="tableTree">

              <el-table :data="mutexProductList"  row-key="id" default-expand-all :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                        @selection-change="batchRenewAddSelectionChange"  class="tableStyle" v-loading="mutexProductListLoading">
                <!-- <el-table-column type="selection" width="55"></el-table-column> -->
                <el-table-column align="left" width="30">
                  <template slot="header" slot-scope="scope">
                    <div class="isAllChecked" v-if="mutexProductList.length > 0">
                      <el-checkbox
                        :indeterminate="isIndeterminateCheck"
                        v-model="isAllChecked"
                        @change="handleCheckedAllChange"
                      ></el-checkbox>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="40">
                  <template slot-scope="scope">
                    <el-checkbox
                      :indeterminate="scope.row.isIndeterminateCheck"
                      v-model="scope.row.isCheck"
                      @change="handleCheckedChange(scope.row,$event)"
                    ></el-checkbox>
                  </template>
                </el-table-column>
                <el-table-column prop="mpCode" label="商品编码" width="200"  align="left"></el-table-column>
                <el-table-column prop="mpName" label="商品名称" width="200"></el-table-column>
                <el-table-column prop="categoryName" label="商品分类" width="200"></el-table-column>
                <el-table-column prop="stock" label="库存" width="200"></el-table-column>
                <el-table-column prop="salePrice" label="原价（元）" width="200"></el-table-column>
                <el-table-column prop="storeName" label="所属商户" width="200"></el-table-column>
                <el-table-column align="center" fixed="right" label="操作" width="390">
                  <template slot-scope="scope">
                    <el-button @click="getMutexInfo(scope.row)" v-if="scope.row.typeOfProduct==20" type="text" class="textButton" size="small">查看详情</el-button>
                    <el-button @click="renewAdd(scope.row)" v-if="scope.row.typeOfProduct==10 || scope.row.typeOfProduct==20" type="text" class="textButton" size="small">重新添加</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div class="toolbar t_r" >
                <el-pagination
                  @size-change="handleSizeChangeMutexProductList"
                  @current-change="handleCurrentChangeMutexProductList"
                  :current-page="mutexProductForm.start"
                  :page-sizes="[10, 20, 30, 40]"
                  :page-size="mutexProductForm.limit"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="mutexProductTotal"
                >
                </el-pagination>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>

      </div>

      <div class="tab-container tab-success createSet" v-show="active==4">
        <div class="titleInfo">
          <img src="/static/images/success.png" />
          <span class="font20">活动创建成功!</span>
        </div>

        <div class="step-button2">
          <el-button class="resetButton" plain @click="detailList">查看活动列表</el-button>
          <template v-if="(4==filters.status && auditCount == 0) || [9,1].includes(filters.status)">
            <kt-button
              class="searchButton"

              :size="size"
              @click="shenheHuodong(0)"
              label="提交审核"
            ></kt-button>
          </template>
          <template v-if="[2].includes(filters.status)">
            <kt-button
              class="searchButton"

              :size="size"
              @click="shenheHuodong(1)"
              label="审核"
            ></kt-button>
          </template>
        </div>
      </div>
    </div>
    <div class="step-button">
      <el-button
        class="cancelButton"
        :plain="active != 1 && active != 4"
        :size="size"
        v-if="active != 1 && active != 4"
        @click="back"
      >上一步</el-button>
      <el-button class="searchButton" :size="size" @click="next" v-show="active!=4">下一步</el-button>
    </div>
    <!-- 选择参与商家 -->
    <el-dialog :title="'添加商家'" :visible.sync="editDialogVisible" :close-on-click-modal="false">
      <div>
        <div >
          <el-form :inline="true" :model="merchantForm" size="mini" ref="merchantForm" :rules="merchantFormRules">
            <el-form-item label="商家编号：" prop="orgNumber" class="w178">
              <el-input v-model="merchantForm.orgNumber"  maxlength="80" placeholder="商家编号" size="mini" clearable></el-input>
            </el-form-item>
            <el-form-item label="商家名称：" prop="name" class="w178">
              <el-input v-model="merchantForm.name" maxlength="80" placeholder="商家名称" size="mini" clearable></el-input>
            </el-form-item>
            <el-form-item label="商家类型：" prop="merchantType" class="w178">
              <el-select v-model="merchantForm.merchantType" placeholder="全部" clearable>
                <!--                <el-option label="全部" value=""></el-option>-->
                <el-option label="自营商家" value="1"></el-option>
                <el-option label="第三方商户" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-row class="t_r mb30 mt20">
            <el-button class="resetButton" size="mini" icon="el-icon-refresh" @click="resetMerchantForm()">重置</el-button>
            <el-button
              class="searchButton"
              size="mini"
              @click="merchantFormFind()"
              icon="el-icon-search"
            >搜索</el-button>
          </el-row>
        </div>
        <div>
          <el-table
            :data="merchantTableData"
            @selection-change="addSelectionChange"
            v-loading="merchantTableDataLoading"
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column align="center" label="商家编号">
              <template slot-scope="scope">
                <span>{{ scope.row.orgNumber}}</span>
              </template>
            </el-table-column>
            <el-table-column width="300px" align="center" label="商家名称">
              <template slot-scope="scope">
                <span>{{ scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column width="300px" align="center" label="商家类型">
              <template slot-scope="scope">
                <span v-if="scope.row.merchantType =='1'">自营商家</span>
                <span v-if="scope.row.merchantType =='2'">第三方商户</span>
              </template>
            </el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar t_r" v-if="merchantTableData.length > 0">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              @current-change="refreshPageRequest"
              :current-page="merchantForm.start"
              :page-size="merchantForm.limit"
              :total="merchantTableDataTatol"
              :page-sizes="[10, 20, 30, 40]"
              @size-change="handleSizeChange"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button class="cancelButton"  :size="size" @click.native="editDialogVisible = false">取消</el-button>
        <el-button
          :size="size"
          class="searchButton"
          @click.native="editDialogVisible = false"
          @click="merchantTableDataSubmit"
        >确定</el-button>
      </div>
    </el-dialog>
    <!-- 导入、上传弹窗-->
    <el-dialog
      :title="operation?'商品导入':'下载模板'"
      class="el-dialog-style"
      :inline="true"
      :visible.sync="uploadVisible"
      :close-on-click-modal="false"
    >
      <div>
        <el-button class="searchButton" icon="el-icon-download" v-show="operation">商品导入模板</el-button>
        <el-button class="searchButton" icon="el-icon-upload" v-show="operation==false">商品导入</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="'互斥提示'"
      :visible.sync="mutexDetailDialogVisible"
      :close-on-click-modal="false"
    >
      <div>
        <div>
          <el-row>
            <el-col class="mb20 t_l">
              <span>以下商品正在参与同类型的促销活动，本次新增将无法生效！</span>
            </el-col>
          </el-row>
          <el-table :data="mutexPromotionTable"  v-loading="mutexPromotionTableLoading">
            <el-table-column align="center" label="互斥活动ID">
              <template slot-scope="scope">
                <span>{{ scope.row.promotionId}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥活动名称">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  class="textButton"
                  @click="seeMoreDeatil(scope.row)"
                >{{ scope.row.promName}}</el-button>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥活动时间">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexTime}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥渠道">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexChannel}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥商户">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexStroeName}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button class="searchButton" :size="size" @click.native="mutexDetailDialogVisible = false">关闭</el-button>
      </div>
    </el-dialog>



    <!-- 互斥活动详情 -->
    <el-dialog :visible.sync="mutexPromotionVisible" title="互斥活动详情" :close-on-click-modal="false">
      <div>
        <el-table :data="mutexPromotionList" ref="multipleTable" :row-class-name="tableRowClassName" :size="size" v-loading="mutexPromotionListLoading">
          <el-table-column prop="promotionCode" width="280" label="互斥活动编码" sortable align="center"></el-table-column>
          <el-table-column prop="promName"   label="互斥活动名称" align="center" class="t_l" width="200">
            <template slot-scope="scope">
              <el-button @click="linkInfoByMutexProduct(scope.row.promotionId,scope.row.promType)" type="text" class="textButton" size="small">{{scope.row.promName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="goodsCategory"  width="360" label="互斥活动时间" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.startTime}} - {{scope.row.endTime}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="storeName" label="活动状态" align="center" width="200">
            <template slot-scope="scope">
              <span class="color333 " v-if="scope.row.status == 0">待提交</span>
              <span class="color333 " v-else-if="scope.row.status == 1">待提交</span>
              <span class="color333 " v-else-if="scope.row.status == 2">待审核</span>
              <span class="color333 " v-else-if="scope.row.status == 3">未开始</span>
              <span class="color333 " v-else-if="scope.row.status == 4">审核不通过</span>
              <span class="color333 " v-else-if="scope.row.status == 5">进行中</span>
              <span class="color333 " v-else-if="scope.row.status == 6">已过期</span>
              <span class="color333 " v-else-if="scope.row.status == 7">已关闭</span>
              <span class="color333 " v-else-if="scope.row.status == 8">已结束</span>
              <span class="color333 " v-else-if="scope.row.status == 9">活动草稿</span>
            </template>
          </el-table-column>
          <el-table-column prop="creatorName" label="创建人" align="center" width="200"></el-table-column>
          <el-table-column prop="deptName"  label="创建组织" align="center" width="200"></el-table-column>
        </el-table>
        <!--分页栏-->
        <div class="toolbar t_r">
          <el-pagination
            @size-change="mutexPromotionListSizeChange"
            @current-change="mutexPromotionListCurrentChange"
            :current-page="mutexPromotionForm.start"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="mutexPromotionForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="mutexPromotionListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button class="searchButton" :size="size" @click.native="mutexPromotionVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import marketRequest from "@/market/request/marketRequest";
  import KtButton from "@/views/Core/KtButton";
  import { format } from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  import { darkmagenta } from "color-name";
  import { quillEditor } from "vue-quill-editor";
  import TreeSelect from "@/views/Core/TreeSelect";
  import "quill/dist/quill.core.css";
  import "quill/dist/quill.snow.css";
  import "quill/dist/quill.bubble.css";
  import { getAllRow, changeChild, changeParent } from "@/assets/js/tableTree.js";
  import {
    singleFrontPromTypesRadio,
    chanelCodesRadio,
    proPlatformRadio,
    proUserTypeRadio,
    proMemberTypeRadio,
    proMemberLevelRadio
  } from "@/market/dict/marketDict";
  const channelArr = ["bbc"];
  const channelArr1 = ["APP端", "PC端", "微信"];
  const channelArr2 = ["新用户", "老用户"];
  const channelArr3 = ["普通会员"];
  const channelArr4 = ["注册用户", "VIP会员", "金卡"];
  export default {
    name: "Tab",
    components: {
      KtButton,
      TableColumnFilterDialog,
      quillEditor,
      TreeSelect
    },
    created: function() {
      this.promotionId = this.$route.query.id;
      if (typeof this.$route.query.active != "undefined") {
        this.active = this.$route.query.active;
      }

    },
    data() {
      var checkOverlayAppNum = (rule, value, callback) => {
        var regEn = /^\+?[1-9][0-9]*$/;
        if (!regEn.test(value)) {
          callback(new Error("请输入正整数"));
        }
        callback();
      };
      /**
       * 校验会员等级
       */
      var checkMemLevel = (rule, value, callback) => {
        //查看每个子平台是否都选中了
        let memberGradeList = this.memberGradeList;
        if(memberGradeList == null || memberGradeList.length < 1){
          return callback(new Error("会员等级不能为空"));
        }
        let flag = false;
        for(var i = 0; i< memberGradeList.length ; i++){
          if((memberGradeList[i].levelSelectList == null || memberGradeList[i].levelSelectList.length < 1 )&& !memberGradeList[i].checkAll){
            flag = true;
            break;
          }
        }
        if(flag){
          return callback(new Error("每个平台必须选中一个会员等级"));
        }
        return callback();
      };
      /**
       * 会员类型
       */
      var checkMemType = (rule, value, callback) => {
        if(this.selectMemTypes == null || this.selectMemTypes.length < 1){
          return callback(new Error("请选择会员类型"));
        }

        return callback();

      };
      var isNumber = (rule, value, callback) => {
        if (value === "") {
          return callback();
        } //这是用来判断如果不是必须输入的，则直接跳出
        const r = /^\+?[1-9][0-9]*$/; // 正整数
        // 如果判断不符合正则，则不是正整数不能提交
        if (!r.test(value)) {
          return callback(new Error("必须为正整数"));
        } else {

          return callback();
        }
      };
      var checkConditonValue = (rule, value, callback) => {
        var r = /^\d+\.?\d{0,2}$/; // 2位小数
        // 如果判断不符合正则，则不是正整数不能提交
        if (!r.test(value)) {
          return callback(new Error("请输入数字(支持2位小数)"));
        } else {
          return callback();
        }
      };
      var checkContentValue = (rule, value, callback) => {
        var reg = /^(?!0(\.0{1,1})?$)(\d(\.\d{1,1})?|10)$/;
        var r = /^\d+\.?\d{0,2}$/; // 2位小数
        if (this.filters.frontPromType == 7 && !reg.test(value)) {
          return callback(new Error("请输入0到10直接的数字(支持1位小数)"));
        }
        if (this.filters.frontPromType == 6 && !r.test(value)) {
          return callback(new Error("请输入数字(支持2位小数)"));
        }
        return callback();
      };
          /**proUserType
            * 新老用户
             */
      var checkUserType = (rule, value, callback) => {
        if(this.selectUserType == null || this.selectUserType.length < 1){
           return callback(new Error("请选择新老用户"));
        }
        return callback();
      };
      var checkWaringNum = (rule, value, callback) => {
        if(value && Number(value) > 100){
          return callback(new Error("必须小于等于100%"));
        }else{
          return callback();
        }
      };
      return {
        merchantFormRules: {
          // orgNumber: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // name: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        storeFormRules: {
          // storename: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // storecode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // merchantName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        merchantSearchFormRules: {
          // orgNumber: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // merchantName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        storeSearchFormRules: {
          // storecode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // storename: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        productFormRules: {
          // goodsName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // thirdSpuId: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // goodsCategory: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // storeName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        merchantProductSearchFormRules: {
          // mpCode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // mpName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
          // categoryName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        },

        auditCount: 0,
        merchantProductTotalCount: 0,
        deptType: localStorage.getItem("deptType"), //当前登录用户所属组织类型
        // 活动时间校验
        timeCheck: {
          disabledDate: time => {
            if (this.promotionStartEndTime) {
              return (
                time.getTime() < Date.now() - 8.64e7 ||
                time.getTime() > new Date(this.promotionStartEndTime).getTime()
              );
            } else {
              return time.getTime() < Date.now() - 8.64e7;
            }
          }
        },
        productTableData2Selection: [], //批量删除时候临时存储
        storeSearchForm: {
          promotionId: this.promotionId,
          merchantType: "2",
          pageNo: 1,
          pageSize: 10,
          orderBys: {
            f: "create_time",
            s: "desc"
          }
        },
        searchMerchantFlag: false,
        searchStoreFlag: false,
        merchantSearchForm: {
          merchantName: null,
          orgNumber:null,
          promotionId: this.promotionId,
          merchantType: "1",
          pageNo: 1,
          pageSize: 10,
          orderBys: {
            f: "create_time",
            s: "desc"
          }
        },
        templateDataForm: {
          templateName: null
        },
        templateDataFormRules: {
          templateName: [
            { required: true, message: "请输入模板名称",trigger:"blur" },
            { required: true, message: "请输入模板名称",trigger:"change" },
            { max: 60, message: "模板名称最多60字符", trigger: "blur" },
            { max: 60, message: "模板名称最多60字符", trigger: "change" }
          ]
        },
        templateDialogVisible: false,
        filtersRules: {
          contentValue: [
            { required: true, validator: checkContentValue, trigger: "change" }
          ],
          conditionValue: [
            { required: true, validator: checkConditonValue, trigger: "change" }
          ],
          freightValue: [{ validator: checkOverlayAppNum, trigger: "change" }],
          freightReducedValue: [
            { validator: checkOverlayAppNum, trigger: "change" }
          ],
          overlayAppNum: [{ validator: checkOverlayAppNum, trigger: "change" }],
          templateDataForm: {
            templateName: null
          },
          templateDialogVisible: false,
          promName: [
            { required: true, message: "请输入活动名称" },
            {
              min: 3,
              max: 60,
              message: "长度在 3 到 60 个字符",
              trigger: "change"
            }
          ],
          budget: [
            { required: true, message: "请输入预警比例", trigger: "blur" }
          ],
          promotionStartEndTime: [
            { required: true, message: "请选择时间", trigger: "blur" }
          ],
          frontPromType: [
            { required: true, message: "请选择促销类型", trigger: "blur" }
          ],
          mainGiftSameFlag: [
            { required: true, message: "请选择赠品类型", trigger: "blur" }
          ],
          overlayAppFlag: [
            { required: true, message: "请选择是否叠加应用", trigger: "blur" }
          ],
          promotionRules: [
            { required: true, message: "请设置优惠设置", trigger: "blur" }
          ],
          parcelsFlag: [
            { required: true, message: "请选择是否包邮", trigger: "blur" }
          ],
          overLimitRule: [
            { required: true, message: "请选择超限规则", trigger: "blur" }
          ],
          costAllocationFlag: [
            { required: true, message: "请选择是否分摊", trigger: "blur" }
          ],
          channelCodes: [
            { required: true, message: "请选择使用渠道", trigger: "blur" }
          ],
          //proUserType: [{ required: true, message: "用户类型", trigger: "blur" }],
          selectUserType: [{ required: true, validator: checkUserType, trigger: "change" }],
          levelSelectList: [{ required: true , validator: checkMemLevel, trigger: "blur"}] ,
          selectMemTypes: [{required: true, validator: checkMemType , trigger: "change"}],
          warningNum:[
            { required: false, validator: checkWaringNum, trigger: "change" },
            { required: false, validator: checkWaringNum, trigger: "blur" }
          ],
        },
        mutexDetailDialogVisible: false,
        mutexPromotionTable: [],
        formLabelWidth: "120px",
        tagCategoryList: [
          {
            id: 1,
            categoryName: "标签分类"
          }
        ],
        // setep3--start
        productPromotionListObject: { productPromotionList: [] },
        productAddSelection: [],
        tableDataTwo: [],
        searchMerchantProductFlag: false,
        merchantProductTableData: [],
        merchantProductTableDataTotal: 0,
        addTagDialogFormVisible: false,
        addTagForm: {
          categoryId: null,
          tagName: null
        },
        dialogVisibleTwo: false,
        tabsIndex: "first",
        labelPosition: "right",
        productForm: {
          start: 1,
          limit: 10,
          goodsName: null,
          storeName: null,
          thirdSpuId: null,
          goodsCategory: null,
          productName: "",
          productNo: "",
          barCode: "",
          chineseName: "",
          code: ""
        },
        // setep3--end
        adminDataForm: {
          auditRemark: null
        },
        adminDataFormRules: {
          auditRemark: [
            { required: true, message: "审核意见不能为空", trigger: "blur" }
          ]
        },
        dialogVisibleAdmin: false,
        shenhe: 0,
        size: "small",
        editDialogVisible: false,
        editDialogVisible2: false,
        url: "./static/shop.png",
        url2: "./static/shop2.png",
        content: null,
        editorOption: {},
        size: "small",
        productVisible: false,
        uploadVisible: false,
        operation: false, // true:商品导入, false:下载模板
        activeName: 0,
        setUp: false,
        search: false,
        tagList: [],
        filters: {
          id: null,
          promType: 1,
          budget:null,
          searchKeyword:null,
          warningNum:null,
          labelId: null,
          promName: null,
          frontPromType: 1,
          foldingFlag: 1,
          overLimitRule: 1,
          channelCodes: null,
          proPlatform: [1],
          proUserType: null,
          proMemberType: [1],
          proMemberLevel: [2],
          createMerchantId: 11,
          contentType: 1,
          status: 9,
          // "creator":1,
          // "creatorName":"wys",
          // "updator":1,
          // "updatorName":"wys",
          rejectCouponsFlag: 0,
          ruleId: null,
          parcelsFlag: 0,
          overlayAppNumFlag: 0,
          overlayAppNum: null,
          description: "",
          conditionValue: null,
          contentValue: null,
          promotionRules: [
            { conditionValue: null, contentValue: null, id: null, level: 1 }
          ],
          mainGiftSameFlag: 1,
          costAllocationFlag: 1,
          templateFlag: 1,
          templateName: null,
          storeArea: -1,
          userArea: -1,
          promotionStartEndTime: [],
          freightType: 1,
          freightValue: null,
          freightReducedValue: null,
          overlayAppFlag: 0
        },
        editLoading: false,
        merchantProductSearchForm: {
          promotionId: null,
          merchantId: null,
          storeId: null,
          mpCode: null,
          mpName: null,
          categoryName: null,
          start: 1,
          limit: 10
        },
        dataForm: {},
        modalShow: 1,
        multipleSelection: [],
        batchDeleteSelection: [],
        repelSelection: [],
        addSelection: [],
        businessList: [{ id: "001", name: "张小二服饰", type: "自营商家" }],
        shopList: [{ id: "161616", name: "张小二bbc店铺", type: "直营" }],
        tableData: [
          {
            id: 1912250010887324,
            productName: "新供应商001",
            unit: "件",
            shopName: "张小二服饰",
            price: 1.2,
            markdown: 1,
            shopLimit1: 100,
            shopLimit2: 100,
            shopLimit3: 100
          },
          {
            id: 1912250010887323,
            productName: "新供应商002",
            unit: "件",
            shopName: "张小二服饰",
            price: 1.3,
            markdown: 1,
            shopLimit1: 100,
            shopLimit2: 100,
            shopLimit3: 100
          }
        ],
        active: this.$route.query.active,
        radio1: 3,
        radio2: 3,
        radio3: 3,
        radio4: 3,
        radio5: 3,
        shopList: [],
        businessList: [],
        checkAll: false,
        checkAll1: false,
        checkAll2: true,
        checkAll3: false,
        checkAll4: false,
        checkedCities: [110001],
        frontPromTypesRadios: singleFrontPromTypesRadio,
        chanelCodesRadios: chanelCodesRadio,
        proPlatformRadios: proPlatformRadio,
        proUserTypeRadios: proUserTypeRadio,
        proMemberTypeRadios: proMemberTypeRadio,
        proMemberLevelRadios: proMemberLevelRadio,
        cities: channelArr,
        cities1: channelArr1,
        cities2: channelArr2,
        cities3: channelArr3,
        cities4: channelArr4,
        isIndeterminate: true,
        isIndeterminate1: true,
        isIndeterminate2: true,
        isIndeterminate3: true,
        isIndeterminate4: true,
        tagCategoryList: [],
        options: [
          {
            value: "1",
            label: "京东直营"
          },
          {
            value: "2",
            label: "淘宝旗舰"
          },
          {
            value: "3",
            label: "良品铺子1店"
          }
        ],
        value5: [],
        options2: [
          {
            value: "1",
            label: "良品铺子"
          }
        ],
        value6: [],
        isClearable: true, // 可清空（可选）
        isAccordion: true, // 可收起（可选）
        valueId: 20, // 初始ID（可选）
        props: {
          // 配置项（必选）
          value: "id",
          label: "name",
          children: "children"
          // disabled:true
        },
        // 选项列表（必选）
        list: [
          { id: 2, parentId: 0, name: "居家生活", rank: 1 },
          { id: 4, parentId: 0, name: "数码家电", rank: 1 },
          { id: 5, parentId: 0, name: "母婴保健", rank: 1 },
          { id: 6, parentId: 0, name: "美食酒水", rank: 2 },
          { id: 7, parentId: 0, name: "个护清洁", rank: 2 },
          { id: 9, parentId: 0, name: "好物甄选", rank: 2 },

          { id: 101, parentId: 2, name: "个护健康", rank: 3 },
          { id: 102, parentId: 2, name: "3C数码", rank: 4 },
          { id: 103, parentId: 2, name: "汽车用品", rank: 5 },
          { id: 202, parentId: 101, name: "按摩电器", rank: 5 },
          { id: 203, parentId: 101, name: "个护美容", rank: 5 }
        ],

        //第一步添加成功赋值
        //外部赋值-----------------start
        promotionId: null,
        auth: 0,
        //外部赋值-----------------start

        promotion: {
          //促销id
          id: "",
          promotionId: "1",
          merchantType: "1"
        },
        pomotionListObject: { pomotionList: [] },
        // pomotionList:[
        //   {
        //   // id:"0",
        //   promotionId:"0",
        //   merchantId:"0",
        //   merchantType:0,
        //   merchantName:"",
        //   storeId:"0",
        //   // createTime:"2020-01-15 11:38:41",
        //   // creator:"0",
        //   // creatorName:"",
        //   // updateTime:"2020-01-15 11:38:41",
        //   // updator:"0",
        //   // updatorName:""
        // }
        // ],
        mainMerchantForm: {
          promotionId: this.promotionId,
          merchantType: "1",
          pageNo: 1,
          pageSize: 10,
          orderBys: {
            f: "create_time",
            s: "desc"
          }
        },
        mainMerchantTableDataTatol: 0,
        //---------------------------商家------------------------------------------------start
        merchantForm: {
          start: 1,
          limit: 10,
          name: null,
          orgNumber: null,
          merchantType:null
        },
        merchantFormStore: {
          start: 1,
          limit: 10
        },
        merchantTableDataTatol: 0,
        merchantTableDataTatolStore: 0,
        merchantTableData: [],
        //选择的商家列表
        merchantTableData2: [],
        promotionStoreTableData: [],
        //---------------------------商家------------------------------------------------end
        storeForm: {
          start: 1,
          limit: 10,
          merchantIds: "",
          storename: "",
          storecode: "",
          orgNumber: "",
          merchantName: "",
          storeType:''
        },

        mainStoreMerchantForm: {
          promotionId: this.promotionId,
          merchantType: "2",
          pageNo: 1,
          pageSize: 10,
          orderBys: {
            f: "create_time",
            s: "desc"
          }
        },
        storeTableDataTatol: 0,
        storeTableData: [],
        //选择店铺
        storeTableData2Tatol: 0,
        storeTableData2: [],
        //选择店铺
        addSelectionStoreTableData2: [],
        merchantTableData2Selection: [],
        merchantTableData2SelectionIndex: 0,
        storeTableDataSelection: [],
        storeTableDataSelectionIndex: 0,

        // -----------------------------------商品开始属性-----------------------------------start

        productTableDataTotal: 0,
        productTableData: [],
        productEditLoading: false,
        productPromotion: {
          //促销id
          promotionId: "1"
        },

        mainProductForm: {
          promotionId: this.promotionId,
          start: 1,
          limit: 10,
          orderBys: {
            f: "create_time",
            s: "desc"
          }
        },

        merchantProductTableDataTotal: 0,


        merchantProductTableDataMutexTotal: 0,
        channelList: [], //渠道Tree List
        channlProps: {
          children: "children",
          label: "childName"
        },

        // -----------------------------------商品结束属性-----------------------------------end

        productStatusTabs: "1" ,   //商品tabs

        mutexMerchantProductTotalCount: 0 ,   //互斥Sku总条数
        mutexProductList: [] ,                //互斥商品List
        mutexProductForm: {
          start : 1,
          limit: 10,
          promotionId: this.promotionId,
          mutexFlag:1,//互斥标识
        },
        mutexProductTotal: 0,                 //互斥分页总条数
        showButtons:true,                     //功能按钮
        mutexPromotionList:[],                //查看详情弹窗
        mutexPromotionListTotal:0,
        mutexPromotionVisible:false,
        mutexPromotionForm:{
          promType: 1,
          start:1,
          limit:10,
        },
        isAllChecked: false,//全选
        isIndeterminateCheck: false,//全选 checkbox 的不确定状态
        allData: [],//全选 操作数据

        isAllProductChecked: false,//全选
        isIndeterminateProductCheck: false,//全选 checkbox 的不确定状态
        allProductData: [],//全选 操作数据

        //会员等级 会员类型
        memberGradeList: [],
        reloadMemLevel: true,

        //会员类型
        memTypeCheckAll: true,
        selectMemTypes:[1,2,3],
        channelId:[1,2,3],
        channelIdCheckAll:true,
        memTypeIsIndeterminate: false,
        channelIdIsIndeterminate:false,
        tableDataTwoLoading: false,
        merchantTableData2Loading: false,
        storeTableDataLoading: false,
        merchantProductTableDataLoading: false,
        mutexProductListLoading: false,
        mutexPromotionTableLoading: false,
        mutexPromotionListLoading: false,
        merchantTableDataLoading: false,
        storeTableData2Loading:false,
        userTypeCheckAll: true,
        selectUserType:[1,2],
        userTypeIsIndeterminate: false,
      };
    },
    methods: {
            //新老用户
      handleCheckAllUserTypeChange(val) {
        this.selectUserType = val ? [1,2] : [];
        this.userTypeIsIndeterminate = false;
      },
       handleCheckedUserTypeChange(value) {
          let checkedCount = value.length;
          this.userTypeCheckAll = checkedCount === 2;
          this.userTypeIsIndeterminate = checkedCount > 0 && checkedCount < 2;
       },
      getUuid() {
        var s = [];
        var hexDigits = "0123456789abcdef";
        for (var i = 0; i < 36; i++) {
          s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
        s[8] = s[13] = s[18] = s[23] = "-";

        var uuid = s.join("");
        return uuid;
      },
      //会员类型
      handleCheckAllMemTypeChange(val) {
        this.selectMemTypes = val ? [1,2,3] : [];
        this.memTypeIsIndeterminate = false;
      },
      handleCheckedMemTypeChange(value) {
        let checkedCount = value.length;
        this.memTypeCheckAll = checkedCount === 3;
        this.memTypeIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },

      //渠道
      handleCheckAllChannelIdChange(val) {
        this.channelId = val ? [1,2,3] : [];
        this.channelIdIsIndeterminate = false;
      },
      handleCheckedChannelIdChange(value) {
        let checkedCount = value.length;
        this.channelIdCheckAll = checkedCount === 3;
        this.channelIdIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },
      //会员等级
      handleMemLevelCheckAllChange(index,checked){
        if(!checked){
          //取消全部
          let memberSelectGrade = this.memberGradeList[index];
          memberSelectGrade.checkAll = false;
          memberSelectGrade.isIndeterminate = false;
          memberSelectGrade.levelSelectList = [];
          // this.$s
          this.$set(this.memberGradeList,index,memberSelectGrade);

        }else{
          //选中全部
          let ids = [];
          this.memberGradeList[index].levelList.forEach(item=>{
            ids.push(item.id)
          })
          let memberSelectGrade = this.memberGradeList[index];
          memberSelectGrade.checkAll = true;
          memberSelectGrade.isIndeterminate = false;
          memberSelectGrade.levelSelectList = ids;
          // this.$s
          this.$set(this.memberGradeList,index,memberSelectGrade);
        }
      },
      memLevelChange(index, levelList){
        //查看当前子平台是否全选
        let levelSelectList = this.memberGradeList[index].levelSelectList;
        if(levelSelectList == null || levelSelectList.length < 1){
          //没有选中子级
          let memberSelectGrade = this.memberGradeList[index];
          memberSelectGrade.checkAll = false;
          memberSelectGrade.isIndeterminate = false;
          memberSelectGrade.levelSelectList = [];
          // this.$s
          this.$set(this.memberGradeList,index,memberSelectGrade);
          return;
        }
        let noSelectIds = [];
        levelList.forEach(item=>{
          if(levelSelectList.indexOf(item.id) == -1){
            //存在
            noSelectIds.push(item.id);
          }
        })

        if(noSelectIds.length < 1){
          //全选
          let ids = [];
          this.memberGradeList[index].levelList.forEach(item=>{
            ids.push(item.id)
          })
          let memberSelectGrade = this.memberGradeList[index];
          memberSelectGrade.checkAll = true;
          memberSelectGrade.isIndeterminate = false;
          memberSelectGrade.levelSelectList = ids;
          this.$set(this.memberGradeList,index,memberSelectGrade);
        }else{
          //没有全选
          let ids = [];
          let memberSelectGrade = this.memberGradeList[index];
          memberSelectGrade.checkAll = false;
          memberSelectGrade.isIndeterminate = true;
          this.$set(this.memberGradeList,index,memberSelectGrade);
        }


      },


      changeSearchMerchantProductFlag(){
        this.searchMerchantProductFlag = !this.searchMerchantProductFlag;
        this.resetForm("merchantProductSearchForm");
      },
      getPromotionStoreTableData(){
        let this_ = this;
        let param = {"promotionId":this.promotionId,"merchantType":2,"pageNo":1, "pageSize":100000};
        this.utils.request.promotionMerchantList(param, res => {
          if (res.code == "0000") {
            this_.promotionStoreTableData = res.data.list.map((ele, index) => {
              let promotionStore = {};
              promotionStore.id = ele.storeId;
              promotionStore.name = ele.storename;
              return promotionStore;
            });
          }
        });
      },
      /**
       * 查询互斥商品
       */
      getMutexProductList() {
        this.mutexProductListLoading = true;
        var this_ = this;
        this.mutexProductForm.promotionId = this.promotionId;
        marketRequest.getProductListV3(this.mutexProductForm, res => {
          if (res.code == "0000") {
            this_.mutexProductList = res.data.rows;
            this_.mutexProductTotal = res.data.total;
            this_.mutexMerchantProductTotalCount = res.data.totalCount;
            //操作数据
            this_.allData = getAllRow(this_.mutexProductList, []);
            this_.isAllChecked = false;
            this_.isIndeterminateCheck = false;
          }
          this_.$nextTick(() =>{
            this_.mutexProductListLoading = false;
          })

        });
      },
      /**
       * 每页条数改变触发
       */
      handleSizeChangeMutexProductList(val){
        this.mutexProductForm.limit = val;
        this.mutexProductForm.start = 1;
        this.getMutexProductList();
      },
      /**
       * 换页刷新
       */
      handleCurrentChangeMutexProductList(val){
        this.merchantProductSearchForm.start = val;
        this.getMutexProductList();
      },

      /**
       * 互斥商品重新添加
       */
      renewAdd(row){
        let that = this;
        let param = {};
        var productIdList = [];
        param.promotionId = row.promotionId;
        param.promotionType = 1;
        if(row.typeOfProduct == '10'){
          row.children.forEach(item=>{
            productIdList.push(item.id);
          })
        }else if(row.typeOfProduct == '20'){
          productIdList.push(row.id);
        }
        param.productIdList = productIdList;
        this.utils.request.renewAddMutexProduct(param,res=>{
          if(res.code=='0000'){
            that.getMutexProductList();
            that.getProductListV2(0, null);

            let data = res.data;
            if(data.businessCode == '0001'){
              this.$message({message: data.businessMsg, type: "success"});
            }else if(data.businessCode == '0002'){
              this.$message({message:data.businessMsg, type: "error"})
            }else if(data.businessCode == '0003'){
              this.$alert(data.businessMsg, '提示', {
                confirmButtonText: '知道了',
                callback: action => {}
              });
            }
          }
        });
      },

      /**
       * 批量重新添加选择数据
       */
      batchRenewAddSelectionChange(val) {
        this.batchRenewAddSelection = val;
      },

      /**
       * 批量重新添加
       */
      batchRenewAdd(){
        let that = this;
        let param = {};
        var productIdList = [];
        param.promotionId = this.promotionId;
        param.promotionType = 1;
        this.allData.forEach(function(item,index,array){
          if(item.typeOfProduct == '20' && item.isCheck){
            productIdList.push(item.id);
          }
        });
        param.productIdList = productIdList;
        this.utils.request.renewAddMutexProduct(param,res=>{
          if(res.code=='0000'){
            that.getMutexProductList();
            that.getProductListV2(0, null);

            let data = res.data;
            if(data.businessCode == '0001'){
              this.$message({message: data.businessMsg, type: "success"});
            }else if(data.businessCode == '0002'){
              this.$message({message:data.businessMsg, type: "error"})
            }else if(data.businessCode == '0003'){
              this.$alert(data.businessMsg, '提示', {
                confirmButtonText: '知道了',
                callback: action => {}
              });
            }
          }
        });
      },
      /**
       * 生效商品 互斥商品tab选中触发
       */
      productTabs(tab){
        if(tab.index==0){
          this.showButtons = true;
        }else{
          this.showButtons = false;
        }
      },
      /**
       * 互斥商品查看详情
       */
      getMutexInfo(row){
        let that = this;
        this.mutexPromotionForm.start = 1;
        this.mutexPromotionForm.limit = 10;
        this.mutexPromotionForm.promotionId = this.promotionId;
        this.mutexPromotionForm.promotionMerchantProductId = row.id;
        this.getPromotionMutexListByProductId();
      },
      getPromotionMutexListByProductId(){
        this.mutexPromotionListLoading = true;
        let that = this;
        this.utils.request.getPromotionMutexListByProductId(this.mutexPromotionForm,res=>{
          if(res.code=='0000'){
            that.mutexPromotionList = res.data.rows;
            that.mutexPromotionListTotal = res.data.total;
            that.mutexPromotionVisible = true;
          }
          that.$nextTick(() =>{
            that.mutexPromotionListLoading = false;
          })
        });
      },

      /**
       * 每页条数改变触发
       */
      mutexPromotionListSizeChange(val){

        this.mutexPromotionForm.limit = val;
        this.mutexPromotionForm.start = 1;
        this.getPromotionMutexListByProductId();
      },
      /**
       * 换页刷新
       */
      mutexPromotionListCurrentChange(val){

        this.mutexPromotionForm.start = val;
        this.getPromotionMutexListByProductId();
      },




      checkProductLimits(row){
        var reg = /^(?!0(\.0{1,1})?$)(\d(\.\d{1,1})?|10)$/;//0-10
        var priceReg = /^\d+\.?\d{0,2}$/; // 2位小数
        var regPos = /^[1-9]([0-9]*)$/; // 非负整数
        var minPrice = row.salePrice.split("~")[0];
        var frontPromTypeDec = '特价';
        if(this.filters.frontPromType == 2){
          frontPromTypeDec = '折扣';
        }else if(this.filters.frontPromType == 3){
          frontPromTypeDec = '直降';
        }
        //stock
        // channelStoreLimit
        // individualLimit
        //contentValue
        if(!row.contentValue || row.contentValue == ''){
          this.$message({ message: "请输入商品"+frontPromTypeDec, type: "error" });
          return false;
        }
        if((this.filters.frontPromType == 1 || this.filters.frontPromType == 3) && !priceReg.test(row.contentValue)){
          this.$message({ message: "正数，支持输入2位小数", type: "error" });
          return false;
        }
        if((this.filters.frontPromType == 1 || this.filters.frontPromType == 3) && Number(row.contentValue) > Number(minPrice)){
          this.$message({ message: row.contentValue + "不能大于 " + minPrice, type: "error" });
          return false;
        }
        if(this.filters.frontPromType == 2 && !reg.test(row.contentValue)){
          this.$message({ message: "请输入0到10直接的数字(支持1位小数)", type: "error" });
          return false;
        }

        if(row.stockLimit && !regPos.test(row.stockLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if (row.parentAllocationScale || row.merchantAllocationScale) {
          if (row.parentAllocationScale && !regPos.test(row.parentAllocationScale)) {
            this.$message({message: "只能输入正整数", type: "error"});
            return false;
          }
          if (row.merchantAllocationScale && !regPos.test(row.merchantAllocationScale)) {
            this.$message({message: "只能输入正整数", type: "error"});
            return false;
          }
          if (Number(row.parentAllocationScale) + Number(row.merchantAllocationScale) != 100) {
            this.$message({message: "平台和商家分摊比例总和不为100", type: "error"});
            return false;
          }
        }
        if(row.individualLimit && !regPos.test(row.individualLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if(row.orderLimit && !regPos.test(row.orderLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if(Number(row.stockLimit) > row.stock){
          this.$message({ message: "活动库存需小于等于商品库存", type: "error" });
          return false;
        }
        if(Number(row.orderLimit) > Number(row.individualLimit)){
          this.$message({ message: "订单限购需小于等于个人限购", type: "error" });
          return false;
        }
        return true;
      },

      getSingleContentLable() {
        if (this.filters.frontPromType == 1) {
          return "特价";
        } else if (this.filters.frontPromType == 2) {
          return "折扣";
        } else {
          return "直降";
        }
      },
      getPromotionDetail(promotionId) {
        //获取促销基本信息详情
        let params = { id: promotionId },
          _this = this;
        this.utils.request.promotionDetailById(params, res => {
          if (res.code == "0000") {
            _this.filters.id = res.data.id;
            _this.filters.promType = res.data.promType;
            _this.filters.promName = res.data.promName;
            _this.filters.searchKeyword = res.data.searchKeyword;
            _this.filters.budget = res.data.budget;
            _this.filters.warningNum = res.data.warningNum;
            _this.filters.frontPromType = res.data.frontPromType;
            _this.filters.foldingFlag = res.data.foldingFlag;
            _this.filters.overLimitRule = res.data.overLimitRule;
            _this.filters.description = res.data.description;
            _this.filters.proPlatform = (res.data.proPlatform + "").split("|");
            _this.filters.proUserType = res.data.proUserType + "";
            _this.filters.proMemberType = (res.data.proMemberType + "").split(
              "|"
            );
            _this.filters.proMemberLevel = (res.data.proMemberLevel + "").split(
              "|"
            );
            _this.filters.storeArea = -1; //(res.data.storeArea + "").split("|");
            _this.filters.userArea = -1; //(res.data.userArea + "").split("|");
            _this.filters.startTime = res.data.startTime;
            _this.filters.endTime = res.data.endTime;
            _this.filters.remark = res.data.remark;
            _this.filters.rejectCouponsFlag = res.data.rejectCouponsFlag;
            _this.filters.parcelsFlag = res.data.parcelsFlag;
            _this.filters.promotionRules = res.data.promotionRules;
            _this.filters.mainGiftSameFlag = res.data.mainGiftSameFlag;
            _this.filters.costAllocationFlag = parseInt(
              res.data.costAllocationFlag
            );
            _this.filters.templateFlag = res.data.templateFlag;
            _this.filters.templateName = res.data.templateName;
            _this.filters.status = res.data.status;
            // _this.filters.promotionStartEndTime[0] = new Date(res.data.startTime);
            // _this.filters.promotionStartEndTime[1] = new Date(res.data.endTime);
            _this.$set(_this.filters, "promotionStartEndTime", [
              new Date(res.data["startTime"]),
              new Date(res.data["endTime"])
            ]);
            _this.filters.labelId = res.data.labelId != null ? Number(res.data.labelId) : null;
            _this.filters.overlayAppFlag = res.data.overlayAppFlag;
            _this.filters.freightType = res.data.freightType;
            _this.filters.freightValue = res.data.freightValue;
            _this.filters.freightReducedValue = res.data.freightReducedValue;
            let selectMemTypes = [];
            res.data.memTypes.split(",").forEach(item=>{
              selectMemTypes.push(Number(item));
            });
            _this.selectMemTypes = selectMemTypes;
            if(selectMemTypes.length < 3){
              this.memTypeIsIndeterminate = true;
              this.memTypeCheckAll = false;this.selectMemTypes
            }
             //新老用户
            let selectUserType = [];
            res.data.proUserType.split(",").forEach(item=>{
               selectUserType.push(Number(item));
            });
            _this.selectUserType = selectUserType;
            if(selectUserType.length < 2){
              this.userTypeIsIndeterminate = true;
              this.userTypeCheckAll = false;
            }
            //渠道
            let channelId = [];
            res.data.channelId.split(",").forEach(item=>{
              channelId.push(Number(item));
            });
            _this.channelId = channelId;
            if(channelId.length < 3){
              this.channelIdIsIndeterminate = true;
              this.channelIdCheckAll = false;this.channelId
            }

          }
        });
      },
      resetStoreForm() {
        //需要校验的keys
        let keys = ["storeType","merchantName","storecode","storename"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.storeForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("storeForm");
        this.storeFormFind();
      },
      resetProductForm() {
        //需要校验的keys
        let keys = ["goodsCategory","thirdSpuId","goodsName","storeName"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.productForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("productForm");
        this.productFormFind();
      },
      resetMerchantForm() {
        //需要校验的keys
        let keys = ["merchantType","name","orgNumber"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.merchantForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("merchantForm");
        this.merchantFormFind();
      },
      addAllProduct() {
        let that_ = this;
        // this.productForm.storeIds = this.storeTableData.map((ele, index) => {
        //   return ele.id;
        // });
        let callback = function(res) {
          if (res.code == "0000") {
            that_.dialogVisibleTwo = false
            // 成功查询本地促销商品
            that_.getProductListV2(0, null);
            that_.getMutexProductList();
          }
        };
        this.productForm.promotionId = this.filters.id;
        marketRequest.promotionMerchantProductAddAll(this.productForm, callback);
      },

      getCurrentStep() {
        return this.active - 1;
      },
      changeContentValue(row) {
        // var reg = /^(?!0(\.0{1,2})?$)(\d(\.\d{1,2})?|10)$/;
        // if(this.filters.frontPromType == 7 && !reg.test(row.contentValue)){
        //   row.contentValue = '';
        // }
      },
      resetMerchantProductSearch() {
        //需要校验的keys
        let keys = ["categoryName","mpName","mpCode","storeId"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.merchantProductSearchForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("merchantProductSearchForm");
        this.merchantProductSearch();
      },
      // 模板下载
      downloadTemplate() {
        window.location.href =
          this.utils.getHost() + "jic-market/resource/download?key=FULL";
      },
      // 批量删除
      batchDelProduct() {
        let ids = [];
        this.allProductData.forEach(function(item,index,array){
          //判断父下面是否全选
          if(item.typeOfProduct == '10' && item.isCheck){
            if(item.children && item.children.length > 0){
              let isCheckItems = item.children.filter(function (subItem, index) {
                return !subItem.isCheck;
              });
              if(!(isCheckItems && isCheckItems.length > 0)){
                ids.push(item.id);
              }
            }else{
              ids.push(item.id);
            }
          }else if(item.typeOfProduct == '20' && item.isCheck){
            ids.push(item.id);
          }
        });
        if (ids.length == 0) {
          this.$message({ message: "未选择删除条目", type: "error" });
          return;
        }

        this.$confirm('确认批量删除已选内容？', "提示", {
          type: "warning",
          closeOnClickModal: false,
        }).then(() => {
          let this_ = this;
          let callback = function(res) {
            if (res.code == "0000") {
              // 成功查询本地促销商品
              this_.getProductListV2(0, null);
            } else {
              this.$message({ message: "删除商品失败", type: "fail" });
            }
          };
          let param = {};
          param.ids = ids;
          marketRequest.promotionMerchantProductDeleteBatch(param, callback);
        }).catch(() => {});
      },

      resetStoreSearch() {
        //需要校验的keys
        let keys = ["storename","storecode"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.storeSearchForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("storeSearchForm");
        this.mainStoreTableDataFormFind();
      },
      storeSearch() {
        this.mainStoreTableDataFormFind();
      },

      resetMerchantSearch() {
        //需要校验的keys
        let keys = ["merchantName","orgNumber"]
        //调用校验
        let  boo = this.seachTableUtils.checkFromIsNull(this.merchantSearchForm,keys)
        if(!boo){
          return;
        }
        this.resetForm("merchantSearchForm");
        this.mainMerchantFormFind();
      },
      merchantSearch() {
        this.mainMerchantFormFind();
      },
      genDescriptionPlaceholder() {
        let placeholder = "最多输入100个字";
        return placeholder;
      },
      handleCurrentChangeMerchantProductTableData(pageNum) {
        this.merchantProductSearchForm.start = pageNum;
        this.getProductListV2(0, null);
      },
      handleSizeChangeMerchantProductTableData(val) {
        this.merchantProductSearchForm.limit = val;
        this.getProductListV2(0, null);
      },
      /*
    备注无法编辑
   */
      changeRemark(val) {
        this.$forceUpdate();
      },
      /**
       * 新增标签弹窗
       */
      addtags() {
        if (this.$refs["addTagForm"] != undefined) {
          this.$refs["addTagForm"].resetFields();
        }
        this.addTagDialogFormVisible = true;
      },
      merchantProductSearch() {
        this.getProductListV2(0, this.merchantProductSearchForm);
      },
      // setep3--start
      seeMoreDeatil(row) {
        this.$router.push(`/FullPromotionDetailNew?id=${row.promotionId}&auth=0`);
      },
      handleClickMerchantProduct(tab, event) {
        if (tab.label == "生效商品") {
          this.getProductListV2(0, null);
        } else {
          this.getProductListV2(1, null);
        }
      },
      //互斥查看更多
      seeMore(row) {
        this.mutexDetailDialogVisible = true;
        this.mutexPromotionTable = [
          {
            promotionId: 26,
            promName: "测试互斥活动1",
            mutexTime: "2019-09-26 14:28:31 - 2019-10-04 14:28:34",
            mutexChannel: "BBC",
            mutexStroeName: "张小二bbc店铺"
          },
          {
            promotionId: 27,
            promName: "测试互斥活动2",
            mutexTime: "2020-01-26 14:28:31 - 2020-02-28 19:45:11",
            mutexChannel: "BBC",
            mutexStroeName: "张小二店铺"
          }
        ];
        //TODO 调用接口获取互斥活动列表
      },
      batchSaveV2() {
        let this_ = this;
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
        this.productPromotionListObject.productPromotionList.splice(
          0,
          this.productPromotionListObject.productPromotionList.length
        );
        for (let i = 0; i < this.productAddSelection.length; i++) {
          let temp = {};
          temp.promotionId = this.promotionId;
          temp.mpId = this.productAddSelection[i].id;
          temp.spuId = this.productAddSelection[i].id;
          this.productPromotionListObject.productPromotionList.push(temp);
        }
        let callback = res => {
          if (res.code == "0000") {
            // 查询本地促销商品
            this_.getProductListV2(0, null);
            this_.getMutexProductList();
          }
        };
        marketRequest.saveBatchV3(this.productPromotionListObject, callback);

        // let this_ = this;
        // this.dialogVisibleTwo = !this.dialogVisibleTwo;
        // this.productPromotionListObject.productPromotionList.splice(0,this.productPromotionListObject.productPromotionList.length);
        // for (let i = 0; i < this.productAddSelection.length; i++) {
        //   let temp = {};
        //   temp.promotionId = this.promotionId;
        //   temp.mpId = this.productAddSelection[i].id;
        //   this.productPromotionListObject.productPromotionList.push(temp);
        // }
        // let callback = res => {
        //   if (res.code == "0000") {
        //     // 查询本地促销商品
        //     this_.getProductListV2(0, null);
        //   }
        // };
        // marketRequest.saveBatchV2(this.productPromotionListObject, callback );
      },

      reloadMutexV2(row) {
        let this_ = this;
        let param = {
          mpId: row.mpId,
          promotionMerchantProductId: row.id,
          promotionId: this.promotionId
        };
        let callback = res => {
          if (res.code == "0000") {
            // 查询本地促销商品
            this_.getProductListV2(1, null);
          }
        };
        marketRequest.reloadMutexV2(param, callback);
      },
      getProductListV2(type, searchParm) {
        this.merchantProductTableDataLoading = true;
        let this_ = this;
        let callback = function(res) {
          if (res.code == "0000") {
            this_.isAllProductChecked = false;
            this_.isIndeterminateProductCheck = false;
            if (type == 0 && res.data.total > 0) {
              this_.merchantProductTableData = res.data.rows;
              this_.merchantProductTableDataTotal = res.data.total;
              this_.merchantProductTotalCount = res.data.totalCount;
              this_.allProductData = getAllRow(this_.merchantProductTableData, [],this_.filters.costAllocationFlag);
            } else {
              this_.merchantProductTableData = [];
              this_.merchantProductTableDataTotal = 0;
              this_.merchantProductTotalCount = 0;
            }
          } else {
          }
          this_.$nextTick(() =>{
            this_.merchantProductTableDataLoading = false;
          })
        };
        this.merchantProductSearchForm.promotionId = this.promotionId;
        marketRequest.getProductListV3(this.merchantProductSearchForm, callback);
      },
      // setep3--
      removePromotionRuleSet(index, val) {
        this.filters.promotionRules.splice(index, 1);
        if (this.promotionId != null && val.id != "undefined") {
          let callback = function(res) {
            if (res.code == "0000") {
            } else {
              //alert("修改失败");
            }
          };
          let param = {
            id: val.id,
            promotionId: this.promotionId
          };
          this.utils.request.promotionRuleDelete(param, callback);
        }
      },
      addPromotionRuleSet() {
        this.filters.promotionRules.push({
          level: this.filters.promotionRules.length + 1
        });
      },
      //更新价格或者限量-todo
      updatePriceOrLimit(val) {
        if(!this.checkProductLimits(val)){
          return;
        }
        let callback = function(res) {
          if (res.code == "0000") {
            val.limitRuleId = res.data;
          } else {
            //alert("修改失败");
          }
        };
        let temp = {};
        temp.id = val.limitRuleId == 0 ? null : val.limitRuleId;
        temp.promotionId = val.promotionId;
        temp.mpId = val.mpId;
        temp.channelStoreLimit = val.channelStoreLimit;
        temp.channelIndividualLimit = val.channelIndividualLimit;
        temp.promPrice = val.promPrice;
        temp.contentValue = val.contentValue;
        temp.individualLimit = val.individualLimit;
        temp.channelMerchantLimit = val.channelMerchantLimit;
        temp.limitType = val.typeOfProduct == 10 ? 5 : 3; //5spu,3sku
        temp.orderLimit = val.orderLimit;
        temp.parentAllocationScale =  val.parentAllocationScale;
        temp.merchantAllocationScale = val.merchantAllocationScale;
        temp.stockLimit = val.stockLimit;
        marketRequest.promotionLimitRuleInsert(temp, callback);
      },
      //批量添加商品
      productSaveBatch() {
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
        this.productPromotionListObject.productPromotionList.splice(
          0,
          this.productPromotionListObject.productPromotionList.length
        );

        for (let i = 0; i < this.productAddSelection.length; i++) {
          let temp = {};
          temp.promotionId = this.promotionId;
          temp.mpId = this.productAddSelection[i].id;
          temp.mpName = this.productAddSelection[i].chineseName; // 商品名称
          temp.merchantName = this.productAddSelection[i].name; //商家名称
          temp.storeName = this.productAddSelection[i].storeName; //店铺名称
          //temp.salePriceWithTax = this.productAddSelection[i].salePriceWithTax;  //零售价
          temp.mpCode = this.productAddSelection[i].code; //商品编码
          temp.mpParentId = this.productAddSelection[i].parentId;
          temp.merchantId = this.productAddSelection[i].merchantId;
          temp.categoryId = this.productAddSelection[i].categoryId;
          // temp.categoryName     = this.productAddSelection[i].categoryName;    类别名称
          temp.picUrl = this.productAddSelection[i].pictureUrl;
          this.productPromotionListObject.productPromotionList.push(temp);

        }

        let callback = res => {
          if (res.code == "0000") {
            // 查询本地促销商品
            this.mainProductTableDataFormFind();
          }
        };

        this.utils.request.promotionMerchantProductSaveBatch(
          this.productPromotionListObject,
          callback
        );
      },
      productTableDataSubmit2() {
        //this.productSaveBatch();
        this.batchSaveV2();
      },
      //确定 选择商品
      productTableData2Click() {
        // 调添加商品 接口
        this.productTableDataSubmit2();
      },
      // 选择商品
      addSelectionChangeProduct(val) {
        let this_ = this;
        this_.productAddSelection = val;
      },

      //修改table header的背景色
      tableHeaderColor({ row, column, rowIndex, columnIndex }) {
        if (rowIndex === 0) {
          return "background-color:rgb(250,250,250);";
        }
      },
      //table的双色条纹
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 1) {
          return "warning-row";
        } else if (rowIndex === 3) {
          return "success-row";
        }
        return "";
      },
      add() {
        this.dialogVisibleTwo = true;
        this.tableDataTwo = [];
        this.productFormFind();
      },
      // 商品方法开始
      productFormFind(start, limit) {
        if (start) {
          this.productForm.start = start;
        }
        if (limit) {
          this.productForm.limit = limit;
        }
        this.tableDataTwoLoading = true;
        let that_ = this;
        this.productForm.storeIds = this.storeTableData.map((ele, index) => {
          return ele.storeId;
        });
        this.productForm.promotionId = this.filters.id;
        marketRequest.promotionSpuPageByPromotionId(this.productForm, function(
          resp
        ) {
          if (resp.code == "0000") {
            if(resp.data.rows == null || resp.data.rows.length < 1){
              that_.tableDataTwo = [];
              that_.productListTotal = 0;
            }else{
              that_.tableDataTwo = resp.data.rows.map((ele, index) => {
                let spu = {};
                spu.id = ele.id;
                spu.code = ele.code;
                spu.chineseName = ele.chineseName;
                spu.totalStock = ele.totalStock;
                spu.goodsCategory = ele.fullNamePath;
                spu.merchantName = ele.merchantName;
                spu.storeName = ele.storeName;
                spu.salePriceScope = ele.salePriceWithTax;
                // spu.measureUnit = ele.measureUnit;
                return spu;
              });
              that_.productListTotal = Number(resp.data.total);
            }
          }
          that_.$nextTick(() =>{
            that_.tableDataTwoLoading = false;
          })
        });
        // let that_ =this;
        // that_.utils.request.queryshopApi(this.productForm, function (resp) {
        //   if (resp.code == "0000") {
        //     that_.tableDataTwo= resp.data.rows;
        //     that_.productListTotal= resp.data.total;
        //   }
        //
        //   that_.tableDataTwo= resp.data.rows;
        // });
      },
      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
        }
      },
      // setep3--end

      shenheHuodong(flag) {
        let _this = this;
        if (flag == 0) {
          this.$confirm("确认提交审核？", "提示", {
            type: "warning"
          })
            .then(() => {
              let callback = res => {
                if (res.code == "0000") {
                  _this.filters.status = 2;
                }
              };
              let param = {};
              param.id = this.promotionId;
              param.status = 2;
              this.utils.request.promotionUpdate(param, callback);
            })
            .catch(() => {});
        } else {
          this.dialogVisibleAdmin = true;
        }
      },
      detailList() {
        this.$router.push({
          path: `/pages/promotionManagement/SinglePromotion`
        });
      },
      submitFormAdminNotPass() {
        this.$refs.adminDataForm.validate(auditRemarkE => {
          if (auditRemarkE) {
            let _this = this;
            let callback = res => {
              if (res.code == "0000") {
                _this.dialogVisibleAdmin = false;
                _this.filters.status = 4;
                _this.auditCount = 1;
              }
            };
            this.adminDataForm.id = this.promotionId;
            this.adminDataForm.status = 4;
            this.utils.request.promotionUpdate(this.adminDataForm, callback);
          }
        });
      },
      submitFormAdmin() {
        let _this = this;
        let callback = res => {
          if (res.code == "0000") {
            _this.dialogVisibleAdmin = false;
            _this.filters.status = 11;
          }
        };
        this.adminDataForm.id = this.promotionId;
        this.adminDataForm.status = 11;
        this.utils.request.promotionUpdate(this.adminDataForm, callback);
      },

      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
        }
      },
      //---------------------------店铺------------------------------------------------start
      //查询店铺
      storeFormFind() {
        //商家 取出商家id-->merchantId
        // this.merchantTableData2;

        let ids = this.merchantTableData2.map(item => item.merchantId).toString();


        let params = [];
        let idArray = (ids + "").split(",");

        for (var i = 0; i < idArray.length; i++) {
          params.push({ id: idArray[i] });
        }

        // mergeTo = mergeTo.concat(mergeFrom);

        if (this.merchantTableData2.length == 0) {
          this.$message({ message: "请先选择商家", type: "success" });
        }
        this.storeTableData2Loading = true;
        // this.merchantTableDataTatol;
        this.storeTableData2.splice(0, this.storeTableData2.length);
        var this__ = this;
        this.storeForm.merchantIds = ids;
        this.utils.request.queryByIds(this.storeForm, function(res) {
          if (res.code == "0000") {
            this__.storeTableData2 = res.data.rows;
            this__.merchantTableDataTatolStore = res.data.total;
          }
          this__.storeTableData2Loading = false;
        });
      },
      storeTableDataselectionChange(val) {
        this.storeTableDataSelection = val;
      },
      merchantTableData2selectionChange(val) {
        this.merchantTableData2Selection = val;
      },
      //选择店铺
      storeTableData2AddSelectionChange(val) {
        this.addSelectionStoreTableData2 = val;
      },
      //确定 选择店铺
      storeTableData2Click() {
        // 调添加店铺 关系接口
        this.merchantTableDataSubmit2();
      },
      merchantTableDataSubmit2() {
        this.storeSaveBatch();

        let callback = res => {
          if (res.code == "0000") {
            this.storeSaveBatch();
          }
        };

        //调接口
        //删除这个活动老的数据
        //批量添加新的数据
        // this.promotion.id=null;
        // this.promotion.promotionId=this.promotionId;
        // this.promotion.merchantType="2";
        //this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
      },

      //批量添加店铺
      storeSaveBatch() {
        let flag = true;
        // this.storeTableData.forEach(res=>{
        //   this.addSelectionStoreTableData2.forEach(item=>{
        //     if(res.storeId == item.id){
        //       this.$message({ message: "不能添加重复店铺", type: "error" });
        //       flag = false;
        //     }
        //   })
        // });
        if (!flag) {
          return;
        }
        this.pomotionListObject.pomotionList.splice(
          0,
          this.pomotionListObject.pomotionList.length
        );

        for (var i = 0; i < this.addSelectionStoreTableData2.length; i++) {
          var temp = {};

          temp.promotionId = this.promotionId;
          temp.storeId = this.addSelectionStoreTableData2[i].id;
          temp.merchantType = "2";
          temp.storeName = this.addSelectionStoreTableData2[i].storeName;
          temp.storeCode = this.addSelectionStoreTableData2[i].storeCode;
          temp.storeType = this.addSelectionStoreTableData2[i].storeType;
          temp.merchantId = this.addSelectionStoreTableData2[i].merchantId;
          temp.merchantName = this.addSelectionStoreTableData2[i].merchantName;
          temp.orgNumber = this.addSelectionStoreTableData2[i].orgNumber;
          this.pomotionListObject.pomotionList.push(temp);
        }

        let callback = res => {
          if (res.code == "0000") {
            this.mainStoreTableDataFormFind();
          }
        };

        this.utils.request.promotionMerchantSaveBatch(
          this.pomotionListObject,
          callback
        );
      },
      //查询绑定关系的店铺
      mainStoreTableDataFormFind() {
        // this.storeTableData
        this.storeTableDataLoading = true;
        this.storeSearchForm.merchantType = "2";
        this.storeSearchForm.promotionId = this.promotionId;
        var this__ = this;
        this.utils.request.promotionMerchantList(this.storeSearchForm, function(
          res
        ) {
          if (res.code == "0000") {
            var ret = [];
            for (var i = 0; i < res.data.list.length; i++) {
              var temp = {};
              temp.promotionId = res.data.list[i].promotionId;
              temp.id = res.data.list[i].id;
              temp.storeId = res.data.list[i].storeId;
              temp.storeName = res.data.list[i].storename;
              temp.storeCode = res.data.list[i].storecode;
              temp.storeType = res.data.list[i].storeType;

              ret.push(temp);
            }
            //店铺调试
            this__.storeTableData = res.data.list;
            this__.storeTableDataTatol = res.data.totalCount;
          }
          this__.$nextTick(() =>{
            this__.storeTableDataLoading = false;
          })

        });
      },

      // 换页刷新
      mainSroreMerchantRefreshPageRequest: function(pageNum) {
        this.mainStoreMerchantForm.pageNo = pageNum;
        this.mainStoreTableDataFormFind();
      },
      // 换页刷新
      mainSroreMerchantHandleSizeChange: function(pageSize) {
        this.mainStoreMerchantForm.pageNo = 1;
        this.mainStoreMerchantForm.pageSize = pageSize;
        this.mainStoreTableDataFormFind();
      },

      // 换页刷新
      refreshPageRequestStore: function(pageNum) {
        this.merchantFormStore.start = pageNum;
        // this.merchantFormFind();
        this.storeFormFind();
      },
      // 换页刷新
      handleSizeChangeStore: function(pageSize) {
        this.merchantForm;
        this.merchantFormStore.limit = pageSize;
        this.merchantFormStore.start = 1;
        this.storeFormFind();
      },

      //---------------------------店铺------------------------------------------------end

      //---------------------------商家------------------------------------------------start

      //---------------------------分页------------------------------------------------start
      // 换页刷新
      refreshPageRequest: function(pageNum) {
        this.merchantForm.start = pageNum;
        this.merchantFormFind();
      },
      // 换页刷新
      handleSizeChange: function(pageSize) {
        this.merchantForm.limit = pageSize;
        this.merchantForm.start = 1;
        this.merchantFormFind();
      },
      producthandleCurrentChange(pageNum) {
        this.productForm.start = pageNum;
        this.productFormFind();
      },
      // 换页刷新
      mainMerchantRefreshPageRequest: function(pageNum) {
        this.mainMerchantForm.pageNo = pageNum;
        this.mainMerchantFormFind();
      },
      producthandleSizeChange(pageSize) {
        this.productForm.start = 1;
        this.productForm.limit = pageSize;
        this.productFormFind();
      },
      // 换页刷新
      mainMerchantHandleSizeChange: function(pageSize) {
        this.mainMerchantForm.pageNo = 1;
        this.mainMerchantForm.pageSize = pageSize;
        this.mainMerchantFormFind();
      },
      //查询绑定关系的商家
      mainMerchantFormFind() {
        this.merchantTableData2Loading = true;
        this.merchantSearchForm.merchantType = "1";
        var this__ = this;
        this.merchantSearchForm.promotionId = this.promotionId;
        this.utils.request.promotionMerchantList(
          this.merchantSearchForm,
          function(res) {
            if (res.code == "0000") {
              var ret = [];
              for (var i = 0; i < res.data.list.length; i++) {
                var temp = {};
                temp.id = res.data.list[i].id;
                temp.name = res.data.list[i].merchantName;
                temp.orgNumber = res.data.list[i].orgNumber;
                temp.merchantType = res.data.list[i].merchantTypeManager;
                temp.merchantId = res.data.list[i].merchantId;
                ret.push(temp);
              }
              this__.merchantTableData2 = ret;
              this__.mainMerchantTableDataTatol = res.data.totalCount;
            }
            this__.$nextTick(() =>{
              this__.merchantTableData2Loading = false;
            })

          }
        );
      },
      // 删除店铺
      storeDelete(id) {
        // this.$confirm("是否确认删除？", "提示", {
        //   type: "warning",
        //   closeOnClickModal: false,
        // })
        //   .then(() => {
        let callback = res => {
          this.mainStoreTableDataFormFind();
          if (res.code == "0000" && res.data == "1") {
            //删除成功再调分页
            this.$message({ message: "删除成功", type: "success" });
          } else {
            this.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        };
        this.promotion.id = id;
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          callback
        );
        // })
        // .catch(() => {});
      },

      //---------------------------分页------------------------------------------------end
      //删除商家
      merchantTableData2delete(id) {
        // this.$confirm("是否确认删除？", "提示", {
        //   type: "warning",
        //   closeOnClickModal: false,
        // })
        //   .then(() => {
        let callback = res => {
          this.mainMerchantFormFind();
          this.mainStoreTableDataFormFind();
          if (res.code == "0000" && res.data == "1") {
            //删除成功再调分页
            this.$message({ message: "删除成功", type: "success" });
          } else {
            this.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        };
        this.promotion.id = id;
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          callback
        );
        // })
        // .catch(() => {});
      },
      //选择商家
      addSelectionChange(val) {
        this.addSelection = val;
      },
      //提交 选择商家
      merchantTableDataSubmit() {
        this.promotionMerchantSaveBatch();
        //this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
      },
      promotionMerchantSaveBatch() {
        let flag = true;
        // this.merchantTableData2.forEach(res=>{
        //   this.addSelection.forEach(item=>{
        //     if(res.merchantId == item.id){
        //       this.$message({ message: "不能添加重复商家", type: "error" });
        //       flag = false;
        //     }
        //   })
        // });
        if (!flag) {
          return;
        }
        this.pomotionListObject.pomotionList.splice(
          0,
          this.pomotionListObject.pomotionList.length
        );

        for (var i = 0; i < this.addSelection.length; i++) {
          var temp = {};

          temp.promotionId = this.promotionId;
          temp.merchantId = this.addSelection[i].id;
          temp.merchantType = "1";
          temp.merchantName = this.addSelection[i].name;
          temp.merchantTypeManager = this.addSelection[i].merchantType;
          temp.orgNumber = this.addSelection[i].orgNumber;
          temp.name = this.addSelection[i].name;

          this.pomotionListObject.pomotionList.push(temp);
        }

        let callback = res => {
          if (res.code == "0000") {
            this.mainMerchantForm.merchantType = "1";
            this.mainMerchantFormFind();
          }
        };

        var this__ = this;
        this.utils.request.promotionMerchantSaveBatch(
          this.pomotionListObject,
          callback
        );
      },
      //查询商家
      merchantFormFind() {
        this.merchantTableDataLoading = true;
        var this__ = this;
        //只有运营平台有使用渠道
        if (this.deptType == 0 && this.filters.channelCodes) {

          this.merchantForm.childIds = this.filters.channelCodes.split(',').map(item => item);
        }
        this.utils.request.queryMerchantList(this.merchantForm, function(res) {
          // this.utils.request.queryMerchantListOther(null, function (res) {
          if (res.code == "0000") {
            this__.merchantTableData = res.data.rows;
            this__.merchantTableDataTatol = res.data.total;
          }
          this__.merchantTableDataLoading = false;
        });
      },
      //---------------------------商家------------------------------------------------end

      //活动渠道
      handleCheckAllChange(val) {
        this.filters.channelCodes = val
          ? chanelCodesRadio.map(function(value, index, array) {
            return value.code;
          })
          : [];
        this.isIndeterminate = false;
      },
      handleCheckedCitiesChange(value) {
        let checkedCount = value.length;
        this.checkAll = checkedCount === this.chanelCodesRadios.length;
        this.isIndeterminate =
          checkedCount > 0 && checkedCount < this.chanelCodesRadios.length;
      },
      //活动平台
      handleCheckAllChange1(val) {
        this.filters.proPlatform = val
          ? proPlatformRadio.map(function(value, index, array) {
            return value.code;
          })
          : [];
        this.isIndeterminate1 = false;
      },
      handleCheckedCitiesChange1(value) {
        let checkedCount = value.length;
        this.checkAll1 = checkedCount === this.proPlatformRadios.length;
        this.isIndeterminate1 =
          checkedCount > 0 && checkedCount < this.proPlatformRadios.length;
      },

      //新老用户
      handleCheckAllChange2(val) {
        this.filters.proUserType = val
          ? proUserTypeRadio.map(function(value, index, array) {
            return value.code;
          })
          : [];
        this.isIndeterminate2 = false;
      },
      handleCheckedCitiesChange2(value) {
        let checkedCount = value.length;
        this.checkAll2 = checkedCount === this.proUserTypeRadios.length;
        this.isIndeterminate2 =
          checkedCount > 0 && checkedCount < this.proUserTypeRadios.length;
      },
      //会员类型
      handleCheckAllChange3(val) {
        this.filters.proMemberType = val
          ? proMemberTypeRadio.map(function(value, index, array) {
            return value.code;
          })
          : [];
        this.isIndeterminate3 = false;
      },
      handleCheckedCitiesChange3(value) {
        let checkedCount = value.length;
        this.checkAll3 = checkedCount === this.proMemberTypeRadios.length;
        this.isIndeterminate3 =
          checkedCount > 0 && checkedCount < this.proMemberTypeRadios.length;
      },
      //会员等级
      handleCheckAllChange4(val) {
        this.filters.proMemberLevel = val
          ? proMemberLevelRadio.map(function(value, index, array) {
            return value.code;
          })
          : [];
        this.isIndeterminate4 = false;
      },
      handleCheckedCitiesChange4(value) {
        let checkedCount = value.length;
        this.checkAll4 = checkedCount === this.proMemberLevelRadios.length;
        this.isIndeterminate4 =
          checkedCount > 0 && checkedCount < this.proMemberLevelRadios.length;
      },
      //添加商家
      querySupplierListForAdd() {
        this.editDialogVisible = true;
        this.promotion.merchantType = 1;
        this.merchantTableData = [];
        this.merchantFormFind();
      },
      //添加店铺
      querySupplierListForAdd2() {
        this.editDialogVisible2 = true;
        this.promotion.merchantType = 2;
        this.storeTableData2 = [];
        this.storeFormFind();
      },
      delAllSelectedSupplierstoreTableData() {
        if (this.storeTableDataSelection.length == 0) {
          this.$message({ message: "未选择删除条目", type: "error" });
          return;
        }
        this.$confirm('确认批量删除已选内容？', "提示", {
          type: "warning",
          closeOnClickModal: false,
        }).then(() => {
          let ids = this.storeTableDataSelection.map(item => item.id).toString();
          let idArray = (ids + "").split(",");
          this.delAllSelectedSupplierstoreTableDataQueryList(idArray);
        }).catch(() => {});

      },
      delAllSelectedSupplierstoreTableDataQueryList(idArray) {
        let that = this;
        this.promotion.merchantType = "2";
        this.promotion.id = idArray[this.storeTableDataSelectionIndex];
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          function() {
            that.storeTableDataSelectionIndex++;
            if (that.storeTableDataSelectionIndex < idArray.length) {
              that.delAllSelectedSupplierstoreTableDataQueryList(idArray);
            } else {
              //执行成功
              that.storeTableDataSelectionIndex = 0;
              that.$message({ message: "删除成功", type: "success" });
              that.mainStoreTableDataFormFind();
            }
          }
        );
      },
      //批量删除商家
      delAllSelectedSuppliermerchantTableData2() {
        if (this.merchantTableData2Selection.length == 0) {
          this.$message({ message: "未选择删除条目", type: "error" });
          return;
        }

        this.$confirm('确认批量删除已选内容？', "提示", {
          type: "warning",
          closeOnClickModal: false,
        }).then(() => {
          let ids = this.merchantTableData2Selection
            .map(item => item.id)
            .toString();
          let idArray = (ids + "").split(",");
          this.delAllSelectedSupplierQueryList(idArray);
        }).catch(() => {});

      },
      delAllSelectedSupplierQueryList(idArray) {
        let that = this;
        this.promotion.merchantType = "1";
        this.promotion.id = idArray[this.merchantTableData2SelectionIndex];
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          function() {
            that.merchantTableData2SelectionIndex++;
            if (that.merchantTableData2SelectionIndex < idArray.length) {
              that.delAllSelectedSupplierQueryList(idArray);
            } else {
              //执行成功
              that.merchantTableData2SelectionIndex = 0;
              that.$message({ message: "删除成功", type: "success" });
              that.mainMerchantFormFind();
              that.mainStoreTableDataFormFind();
            }
          }
        );
      },

      // ------------------------------------商品开始方法-------------------------------------start

      // 换条数刷新
      handleSizeChangeForProduct: function(pageSize) {
        this.productForm.limit = pageSize;
        this.productForm.start = 1;
        this.productFormFind();
      },

      // 换页刷新
      handleCurrentChangeForProduct: function(pageNum) {
        this.productForm.start = pageNum;
        this.productFormFind();
      },
      //
      // // 查询商品
      // productFormFind(){
      //   let that_ =this;
      //   that_.utils.request.queryPageProductManagement(this.productForm, function (resp) {
      //     //
      //     if (resp.code == "0000") {
      //       that_.productTableData= resp.data.rows;
      //       that_.productTableDataTotal = resp.data.total;
      //     }
      //   });
      // },

      // 商品多项目选择
      productSelectionChange(val) {
        // this.storeTableDataSelection=val;
      },

      // 选择商品
      addSelectionChangeProduct(val) {
        let this_ = this;
        this_.productAddSelection = val;
      },

      // //确定 选择商品
      // productTableData2Click(){
      //   //
      //   // 调添加商品 接口
      //   this.productTableDataSubmit2();
      // },
      // productTableDataSubmit2(){
      //
      //   this.productSaveBatch();
      //   // let callback = res => {
      //   //   //
      //   //   if (res.code == "0000") {
      //   //     this.productSaveBatch();
      //   //   }
      //   // };
      //   //
      //   // //调接口
      //   // //删除这个活动老的数据
      //   // //批量添加新的数据
      //   // this.promotion.id=null;
      //   // this.promotion.promotionId=this.promotionId;
      //   // this.promotion.merchantType="2";
      //   // //  TODO 下面可以不用删除
      //   // this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
      // },

      //批量添加商品
      // productSaveBatch(){
      //   //
      //   //
      //   //
      //   this.productPromotionListObject.productPromotionList.splice(0,this.productPromotionListObject.productPromotionList.length);
      //   //
      //   //
      //   //
      //
      //   for (var i = 0; i < this.productAddSelection.length; i++) {
      //     var temp = {};
      //     temp.promotionId         = this.promotionId;
      //     temp.mpId           =  this.productAddSelection[i].id;
      //     temp.mpName         =  this.productAddSelection[i].chineseName; // 商品名称
      //     temp.merchantName         =  this.productAddSelection[i].name;  //商家名称
      //     temp.mpCode         =  this.productAddSelection[i].code;  //商品编码
      //     temp.mpParentId       = this.productAddSelection[i].parentId;
      //     temp.merchantId       = this.productAddSelection[i].merchantId;
      //     temp.categoryId        = this.productAddSelection[i].categoryId;
      //     // temp.categoryName     = this.productAddSelection[i].categoryName;    类别名称
      //     temp.picUrl        = this.productAddSelection[i].pictureUrl;
      //     this.productPromotionListObject.productPromotionList.push(temp);
      //   }
      //   //
      //   //
      //   //
      //
      //   let callback = res => {
      //     //
      //     if (res.code == "0000") {
      //       // 查询本地促销商品
      //       this.mainProductTableDataFormFind();
      //     }
      //   };
      //
      //   this.utils.request.promotionMerchantProductSaveBatch(this.productPromotionListObject, callback );
      //
      // },

      //查询促销商品
      mainProductTableDataFormFind() {
        this.mainProductForm.promotionId = this.promotionId;
        let this_ = this;
        this.utils.request.promotionMerchantProductList(
          this.mainProductForm,
          function(res) {
            ////
            if (res.code == "0000") {
              // let ret = [];
              // for (let i = 0; i < res.data.list.length; i++) {
              //   var temp = {};
              //   temp.mpCode          = res.data.list[i].mpCode;
              //   temp.productName                   = res.data.list[i].mpName;
              //   temp.barcode              = res.data.list[i].barcode;
              //   // temp.unit            = res.data.list[i].unit;
              //   temp.merchantName            = res.data.list[i].merchantName;
              //   ret.push(temp);
              // }
              //
              this_.merchantProductTableData = res.data.rows;
              this_.merchantProductTableDataTotal = res.data.total;
            }
          }
        );
      },

      // ------------------------------------商品结束方法-------------------------------------end

      addActive() {
         if (parseInt(this.active) === 1) {
          this.active = parseInt(this.active) + 2;
        } else {
          this.active = parseInt(this.active) + 1;
        }
        this.$router.push({ query: { id: this.promotionId ,auth:0,active:this.active} })
        if (this.active > 4) {
          this.$router.push({
            path: "/pages/promotionManagement/singlePromotion"
          });
        }
      },
      back() {
        if (parseInt(this.active) === 3) {
          this.active = parseInt(this.active) - 2;
        } else {
          this.active = parseInt(this.active) - 1;
        }
        this.$router.push({ query: { id: this.promotionId ,auth:0,active:this.active} })
        this.nextOrBack();
      },
      next() {
        let _this = this;
        let callback = function(res) {
          if (res.code == "0000") {
            _this.promotionId = res.data;
            _this.filters.id = res.data;
            _this.promotion.promotionId = res.data;
            _this.mainMerchantForm.promotionId = res.data;
            _this.mainStoreMerchantForm.promotionId = res.data;
            _this.addActive();
            // _this.mainMerchantFormFind();
            // _this.mainStoreTableDataFormFind();
            //_this.$router.push({ query: { id: res.data ,auth:0,active:_this.active} })
          } else {
            _this.$message({ message: "操作失败", type: "fail" });
            _this.active = 1;
          }
        };
        let callbackUpdate = function(res) {
          if (res.code == "0000") {
            _this.addActive();
            //_this.$router.push({ query: { id: res.data ,auth:0,active:_this.active} })
            // _this.mainMerchantFormFind();
            // _this.mainStoreTableDataFormFind();
          } else {
            _this.$message({ message: "操作失败", type: "fail" });
            _this.active = 1;
          }
        };
        //保存活动基础配置
        if (this.active == 1) {
          this.$refs["filters"].validate(valid => {
            if (valid) {

              this.filters.startTime = this.filters.promotionStartEndTime[0];
              this.filters.endTime = this.filters.promotionStartEndTime[1];
              if(this.deptType == 3){
                this.filters.costAllocationFlag = 1;
                this.filters.storeAllocationScale = 100;
              }
              //保存会员等级 会员类型
              this.filters.memTypes = this.selectMemTypes.join(",")
              this.filters.proUserType = this.selectUserType.join(",");
              this.filters.channelId = this.channelId.join(",");
              if (this.promotionId == null) {
                if( new Date(this.filters.startTime) < new Date()){
                  this.$message({
                    message: "开始时间不能小于当前时间,请修改活动时间"
                  });
                  return;
                }
                this.utils.request.promotionCreate(this.filters, callback);
              } else {
                if (
                  this.filters.status == 9 &&
                  new Date(this.filters.startTime) < new Date()
                ) {
                  this.$message({
                    message: "草稿状态下开始时间不能小于当前时间,请修改活动时间"
                  });
                } else {
                  this.utils.request.promotionUpdate(
                    this.filters,
                    callbackUpdate
                  );
                }
              }
            }
          });
        }else if (this.active == 3) {//更新活动状态
          if (this.active == 3 && this.merchantProductTableData.length == 0) {
            _this.$message({ message: "商品未添加", type: "fail" });
            return;
          }
          for (let i = 0; i < this.merchantProductTableData.length; i++) {
            if(!this.checkProductLimits(this.merchantProductTableData[i])){
              return;
            }
            if(this.merchantProductTableData[i].children.length>0) {
              for (var j = 0; j < this.merchantProductTableData[i].children.length; j++) {
                if (!this.checkProductLimits(this.merchantProductTableData[i].children[j])) {
                  return;
                }
              }
            }
          }
          for (let i = 0; i < this.merchantProductTableData.length; i++) {
            if(!this.checkProductLimits(this.merchantProductTableData[i])){
              return;
            }
          }
          if (this.filters.status == 9) {
            let callback = function(res) {};
            this.filters.status = 1;
            this.utils.request.promotionUpdateStatus(this.filters, callback);
          }
          this.addActive();
        }else if (this.active == 2) {
          if (
            this.storeTableData.length == 0 ||
            this.merchantTableData2.length == 0
          ) {
            //判断商家店铺
            _this.$message({ message: "商家或店铺未添加", type: "fail" });
            return;
          }
          this.getProductListV2(0, null);
          this.getMutexProductList();
          this.getPromotionStoreTableData();
          this.addActive();
        }else if (this.active == 4) {
          this.$message({ message: "操作成功", type: "success" });
          return;
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //批量选择删除商品
      handleBatchDeleteSelection(val) {
        this.batchDeleteSelection = val.map(item => {
          return item.id;
        });
      },
      //批量删除商品-todo
      delBatchMerchantProducts(ids) {
        let callback = function(res) {
          if (res.code == "0000") {
            //成功后重新获取一下商家商品列表
          } else {
            alert("删除失败");
          }
        };
        let param = { ids: ids };
        this.utils.request.promotionMerchantProductDeleteBatch(param, callback);
      },

      //删除促销商品-todo
      delMerchantProducts(id) {
        // this.$confirm("是否确认删除活动？", "提示", {
        //   type: "warning",
        //   closeOnClickModal: false,
        // })
        //   .then(() => {
        let this_ = this;
        let callback = function(res) {
          if (res.code == "0000") {
            // 成功查询本地促销商品
            this_.getProductListV2(0, null);
          } else {
            this_.getProductListV2(0, null);
            alert("删除失败");
          }
        };
        let param = {};
        param.id = id;
        marketRequest.promotionMerchantProductDelete(param, callback);
        // })
        // .catch(() => {});

        // this.$confirm("是否确认删除活动？", "提示", {
        //   type: "warning"
        // })
        //   .then(() => {
        //     let this_ =this;
        //     let callback = function(res) {
        //       if (res.code == "0000") {
        //         // 成功查询本地促销商品
        //         this_.mainProductTableDataFormFind();
        //       } else {
        //         this_.mainProductTableDataFormFind();
        //         alert("删除失败");
        //       }
        //     };
        //     let param ={};
        //     param.promotionId         =promotionId;
        //     param.mpId           =mpId;
        //     this.utils.request.promotionMerchantProductDelete(param, callback);
        //   })
        //   .catch(() => {
        //   });
      },

      // //更新价格或者限量-todo
      // updatePriceOrLimit(val){
      //   //
      //   let callback = function(res) {
      //     if (res.code == "0000") {
      //
      //     } else {
      //       //alert("修改失败");
      //     }
      //   };
      //   this.utils.request.promotionMerchantProductUpdatePriceOrLimit(val, callback);
      // },
      repelSelectionChange(val) {
        this.repelSelection = val;
      },
      createPage() {
        this.$router.push("/CreatePromotion");
      },
      handleClick(tab, event) {
        ////
        if (tab.name == "0") {
          // 触发‘配置管理’事件
          this.first();
        } else {
          // 触发‘用户管理’事件
          this.second();
        }
      },
      first() {
        ////
        this.modalShow = 1;
      },
      second() {
        ////
        this.modalShow = 2;
      },
      //添加商品弹窗
      productSelectionModal() {
        this.productVisible = true;
      },
      showBatchSetUp() {
        if (this.search == true) {
          this.search = false;
        }
        if (this.setUp == false) {
          this.setUp = true;
        } else if (this.setUp == true) {
          this.setUp = false;
        }
      },
      showQueryCondition() {
        if (this.setUp == true) {
          this.setUp = false;
        }
        if (this.search == false) {
          this.search = true;
        } else if (this.search == true) {
          this.search = false;
        }
      },
      batchReAdd() {
        if (this.multipleSelection.length < 1) {
          this.$message({ message: "请选择要设置的商品", type: "error" });
          return false;
        }
        this.$message({ message: "操作成功", type: "success" });
      },
      updatePriceAndLimit() {},
      importCommodityModal(val) {
        if (val === 1) {
          this.operation = true;
        } else if (val == 2) {
          this.operation = false;
        }
        this.uploadVisible = true;
      },
      // 取值
      getValue(value) {
        this.valueId = value;
        ////
      },
      handleCheckChange(data, checked, indeterminate) {
        ////
        ////
      },
      handleClose() {
        ////
      },
      /**
       * 点击活动名称跳转详情
       */
      linkInfoByMutexProduct(promotionId,type){
        if(type == 1){
          this.$router.push({ path: "/SinglePromotionDetail/" + promotionId + "/0"});
          //this.$router.push(`/SinglePromotionDetail?id=${promotionId}&auth=0`);
        }else if(type == 2){
          this.$router.push(`/FullNumPromotionDetailNew?id=${promotionId}&auth=0`);
        }else if(type == 3){
          this.$router.push({ path: "/FullPromotionDetailNew/" + promotionId + "/0"});
          //this.$router.push(`/FullPromotionDetailNew?id=${promotionId}&auth=0`);
        }else if(type == 4){
          this.$router.push(`/SeckillDetail?promotionId=${promotionId}`);
        }else if(type == 5){
          this.$router.push({ path: "/GiftPromotionDetail/" + promotionId + "/0"});
          //this.$router.push(`/GiftPromotionDetail?id=${promotionId}&auth=0`);
        }else if(type == 6){
          this.$router.push({ path: "/ComplexPromotionInfo/" + promotionId});
        }else if(type == 7){
          this.$router.push({ path: "/XofferPromotionDetail/" + promotionId + "/0"});
          //this.$router.push(`/XofferPromotionDetail?id=${promotionId}&auth=0`);
        }else if(type == 8){
          this.$router.push({ path: "/IncreasePromotionDetail/" + promotionId + "/0"});
          //this.$router.push(`/IncreasePromotionDetail?id=${promotionId}&auth=0`);
        }else if(type == 9){
          this.$router.push(`/QueryPresellPromotion?value=${promotionId}&auth=0`);
        }else if(type == 10){
          this.$router.push("/GroupDetailPromotion?id=" + `${promotionId}`);
        }else if(type == 12){
          this.$router.push(`/QueryPromotion?value=${promotionId}&auth=0`);
        }
      },
      nextOrBack(){
        //根据当前url中active参数判断执行第几步方法
        if (this.active){
          if (parseInt(this.active) == 2){
            this.$nextTick(() =>{
              this.mainMerchantFormFind();
              this.mainStoreTableDataFormFind();
            })
          }else if(parseInt(this.active) == 3){
            this.$nextTick(()=>{
              this.getProductListV2(0, null);
              this.getMutexProductList();
              this.getPromotionStoreTableData();
            })

          }
        }
      },
      handleCheckedAllChange(value) {
        ////
        this.isIndeterminateCheck = false;

        this.allData.forEach(f => {
          f.isCheck = value;
          f.isIndeterminateCheck = false;
        });
      },
      handleCheckedChange(row, checked) {
        ////
        if (row.isIndeterminateCheck) {
          row.isCheck = true;
          checked = true;
        }
        row.isIndeterminateCheck = false;

        changeChild(row, checked);
        changeParent(row, this.allData);

        this.isAllChecked = this.allData.every(e => {
          return e.isCheck;
        });

        this.isIndeterminateCheck =
          !this.isAllChecked &&
          this.allData.some(e => {
            return e.isCheck;
          });
      },

      handleCheckedAllProductChange(value) {
        ////
        this.isIndeterminateProductCheck = false;

        this.allProductData.forEach(f => {
          f.isCheck = value;
          f.isIndeterminateCheck = false;
        });
      },
      handleCheckedProductChange(row, checked) {
        ////
        if (row.isIndeterminateCheck) {
          row.isCheck = true;
          checked = true;
        }
        row.isIndeterminateCheck = false;

        changeChild(row, checked);
        changeParent(row, this.allProductData);

        this.isAllProductChecked = this.allProductData.every(e => {
          return e.isCheck;
        });

        this.isIndeterminateProductCheck =
          !this.isAllProductChecked &&
          this.allProductData.some(e => {
            return e.isCheck;
          });
      },

    },
    computed: {
      /* 转树形数据 */
      optionData() {
        let cloneData = JSON.parse(JSON.stringify(this.list)); // 对源数据深度克隆
        return cloneData.filter(father => {
          // 循环所有项，并添加children属性
          let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
          branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性，并赋值
          return father.parentId == 0; //返回第一层
        });
      }
    },
    mounted() {
      //活动id
      //0-创建-1-编辑；
      this.auth = this.$route.query.auth;
      this.active = this.$route.query.active;
      this.promotionId = this.$route.query.id;

      if (typeof this.$route.query.id != "undefined") {
        this.promotion.id = this.$route.query.id;

        this.getPromotionDetail(this.promotionId);
      }


      //根据当前url中active参数判断执行第几步方法
      this.nextOrBack();



    }
  };
</script>

<style scoped lang="scss">
@import '../../../assets/css/public.scss';
/deep/ .is-bordered{
  padding: 12px 20px 12px 10px;
}
.mleft10 {
  margin-right: 10px;
}
.flexBox{
  display: flex;
  flex-wrap: nowrap;
  align-content: flex-start;
  .child-name{
    flex-shrink: 0;
  }
  .checkboxes{
    display: flex;

  }

}
.w126{
  width: 126px;
}
.oe{
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.width100{
  width: 97px;
}
.w104{
  width: 104px;
}
.ml60{
  margin-left: 60px;
}
.pdl30{
  padding-left: 30px;
}
.pdt20{
  padding-top: 20px;
}
.labelAlignment{
  /deep/ .el-form-item__label{
    height: 33px !important;
    line-height: 33px !important;
  }
}
.w144{
  width: 144px !important;
}
.width450{
  width: 450px !important;
  /deep/ .el-input__inner{
    width: 450px !important;
  }
}
.contentPadding{
  /deep/ .el-form-item__content{
    padding-top: 8px !important;
  }
}
</style>
